/*
 * @Author: YKH
 * @Date: 2022-04-25 11:45:04
 * @LastEditTime: 2022-05-09 11:37:29
 * @Description: 
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\task\controller\admin\flag.ts
 */
import { Inject, Post, Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { ShuyouTargetFlagEntity } from '../../entity/flag';
import { ShuyouTargetFlagService } from '../../service/flag';

/**
 * 
 */
@Provide()
@CoolController({
    // 添加通用CRUD接口
    api: ['add', 'delete', 'update', 'info', 'list', 'page'],
    // 设置表实体
    entity: ShuyouTargetFlagEntity,
    service: ShuyouTargetFlagService,
    before: ctx => {
        //前段数据转JSON格式
        const data = ctx.request.body;
        ctx.request.body.data = JSON.stringify(data);
    },

})
export class ShuyouTargetFlagController extends BaseController {
    @Inject()
    ShuyouTargetFlagService: ShuyouTargetFlagService;


    @Post('/getTodayFlag')
    async getTodayFlag() {
        let getTodayFlag = await this.ShuyouTargetFlagService.getTodayFlag('todayFlag');
        // console.log(getTodayFlag)
        if (!getTodayFlag) {
            return await this.fail('未查询到标记', -1);
        } else if (getTodayFlag.code == 1000) {
            return await this.ok({ code: 1000, message: getTodayFlag.data });
        } else {
            // return await this.fail(getTodayFlag.data, -1);
            return await this.ok({ code: -1, message: getTodayFlag.data });
        }
    }
}
