|
@@ -5,12 +5,16 @@ import { BaseService, ServiceError } from 'free-midway-component';
|
|
|
import { User } from '../../entity/system/user.entity';
|
|
|
import { I18nService } from '../i18n.service';
|
|
|
import { FrameErrorEnum } from '../../error/frame.error';
|
|
|
+import { Record } from '../../entity/core/record.entity';
|
|
|
type modelType = ReturnModelType<typeof User>;
|
|
|
@Provide()
|
|
|
export class UserService extends BaseService<modelType> {
|
|
|
@InjectEntityModel(User)
|
|
|
model: modelType;
|
|
|
|
|
|
+ @InjectEntityModel(Record)
|
|
|
+ rModel: ReturnModelType<typeof Record>;
|
|
|
+
|
|
|
@Inject()
|
|
|
i18n: I18nService;
|
|
|
|
|
@@ -21,4 +25,17 @@ export class UserService extends BaseService<modelType> {
|
|
|
if (user && user._id) throw new ServiceError(this.i18n.translateError(FrameErrorEnum.USER_EXIST), FrameErrorEnum.USER_EXIST);
|
|
|
return data;
|
|
|
}
|
|
|
+
|
|
|
+ // 查询用户详情
|
|
|
+ async detail(id) {
|
|
|
+ const course = await this.rModel.find({ user_id: id }, { hour: 1 }).lean();
|
|
|
+ const numbers = [];
|
|
|
+ for (const val of course) {
|
|
|
+ numbers.push(parseInt(val.hour) || 0);
|
|
|
+ }
|
|
|
+ const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
|
+ await this.model.updateOne({ _id: id }, { hour: sum });
|
|
|
+ const user = await this.model.findById(id).lean();
|
|
|
+ return user;
|
|
|
+ }
|
|
|
}
|