/*
 * @Author: YKH
 * @Date: 2021-12-08 10:26:27
 * @LastEditTime: 2022-09-27 18:27:43
 * @Description:
 * @FilePath: \cool-admin\cool-admin-midway-master\src\app\modules\shuyou\controller\admin\rent_computer.ts
 */
import { Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from 'midwayjs-cool-core';
import { ShuyouRentLedgerComputerEntity } from '../../entity/rent_ledger_computer';
import { ShuyouRentLedgerComputerService } from '../../service/rent_ledger_computer';

/**
 * 租机
 */
@Provide()
@CoolController({
  // 添加通用CRUD接口
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  // 设置表实体
  entity: ShuyouRentLedgerComputerEntity,
  service: ShuyouRentLedgerComputerService,
  // // 向表插入当前登录用户ID
  // insertParam: async (ctx: Context) => {
  //   return {
  //     userId: ctx.admin.userId,
  //   };
  // },
  // // info接口忽略价格字段
  // infoIgnoreProperty: ['price'],

  before: ctx => {
    //前段数据转JSON格式
    const data = ctx.request.body;
    if (typeof data.new_date == 'undefined') {
      data.new_date = [new Date(), new Date()];
    }
    ctx.request.body.data = JSON.stringify(data);
  },
  // 分页查询配置
  pageQueryOp: {
    // 让字段支持模糊查询
    keyWordLikeFields: ['pc_num'],
    // 让字段支持筛选
    fieldEq: ['pc_num'],
    // 添加排序
    addOrderBy: {
      // 排序字段及排序方式
      pc_num: 'asc',
    },
  },
})
export class ShuyouRentLedgerComputerController extends BaseController {}
