nihao b7c487fe40 新曾字段position 5 gadi atpakaļ
..
README.md 5a9d34cb77 0314 7 gadi atpakaļ
column.js 53481a38ef 菜单增加字段 5 gadi atpakaļ
menu.js b7c487fe40 新曾字段position 5 gadi atpakaļ
news.js f9d675cb9c delete & restore方法指定async 6 gadi atpakaļ
site.js c6ab8084ee 完成服务和测试 6 gadi atpakaļ

README.md

CRUD服务

'use strict';

const ObjectID = require('mongodb').ObjectID;
const assert = require('assert');
const util = require('core-util-is');
const { BusinessError, ErrorCode } = require('naf-core').Error;
const { CrudService } = require('naf-framework-mongoose').Services;

class CategoryService extends CrudService {
  constructor(ctx) {
    super(ctx);
    this.model = ctx.model.Category;
    this.mItems = ctx.model.Items;
  }

  async delete({ id }) {
    assert(id);

    // TODO:检查数据是否存在
    const entity = await this._findOne({ _id: ObjectID(id) });
    if (util.isNullOrUndefined(entity)) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);

    // TODO: 检查是否包含字典项数据
    const count = await this._count({ category: entity.code }, this.mItems);
    if (count > 0) {
      throw new BusinessError(ErrorCode.SERVICE_FAULT, '存在字典项数据,不能删除');
    }

    await this._remove({ _id: ObjectID(id) });
    return 'deleted';
  }

  // async query({ skip, limit, order } = {}, data = {}) {
  //   // const rs = await this._find(trimData(data), null, trimData({ skip, limit, sort: order && { [order]: 1 } }));
  //   const rs = await this.model.find({}, null, {}).exec();
  //   return rs;
  // }

}

module.exports = CategoryService;