'use strict'; const assert = require('assert'); const _ = require('lodash'); const { ObjectId } = require('mongoose').Types; const { CrudService } = require('naf-framework-mongoose/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; class LookuserService extends CrudService { constructor(ctx) { super(ctx, 'lookuser'); this.model = this.ctx.model.Lookuser; this.rmodel = this.ctx.model.Roomuser; } async create(data) { const { roomname, userid } = data; const lookuser = await this.model.findOne({ roomname, userid }); if (!lookuser) { await this.model.create(data); } } async query({ skip, limit, ...info }) { const total = await this.model.count(info); const lookuser = await this.model .find(info) .skip(Number(skip)) .limit(Number(limit)); const data = []; for (const _lookuser of lookuser) { const lu = JSON.parse(JSON.stringify(_lookuser)); const ruser = await this.rmodel.findById(_lookuser.userid); const _ruser = JSON.parse(JSON.stringify(ruser)); const newdata = { ...lu, ..._ruser }; data.push(newdata); } return { data, total }; } } module.exports = LookuserService;