/** * @author songxiwen * @date 2020/09/22 17:43 */ import { Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; import { AdminOperationAuth } from '../model/admin.operation.auth'; import { BaseService } from '../../../base/base.service'; import { MongoDBCollection } from '../../../constant'; @Injectable() export class AdminOperationAuthService extends BaseService { constructor( @InjectModel(MongoDBCollection.AdminOperationAuth) protected readonly model: Model ) { super(model); } async getOperationMap(): Promise<{ [key: string]: { key: string; name: string; id: string; }; }> { const operationList = await this.model.find(); return operationList.reduce( ( previousValue: { [key: string]: { key: string; name: string; id: string; }; }, currentValue: AdminOperationAuth ) => ({ ...previousValue, [currentValue._id.toString()]: { id: currentValue._id.toString(), name: currentValue.name, key: currentValue.key } }), {} ); } }