personalscore.js 806 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class PersonalscoreService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'personalscore');
  10. this.model = this.ctx.model.Personalscore;
  11. }
  12. async opera({ data }) {
  13. const cList = data.filter(f => !(f.id || f._id));
  14. const uList = data.filter(f => f.id || f._id);
  15. console.log(cList);
  16. console.log(uList);
  17. for (const i of cList) {
  18. await this.model.create(i);
  19. }
  20. for (const i of uList) {
  21. await this.model.findByIdAndUpdate(i.id || i._id, i);
  22. }
  23. }
  24. }
  25. module.exports = PersonalscoreService;