/** * @author songxiwen * @date 2020/09/18 14:35 */ import { Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; import { AdminRole } from '../model/admin.role'; import { BaseService } from '../../../base/base.service'; import { MongoDBCollection } from '../../../constant'; import { AdminRoleForResponseType } from '../type'; @Injectable() export class AdminRoleService extends BaseService { constructor( @InjectModel(MongoDBCollection.AdminRole) protected readonly model: Model ) { super(model); } async getRoleMap(): Promise<{ [key: string]: AdminRoleForResponseType }> { const roleList = await this.model.find(); return roleList.reduce( ( previousValue: { [key: string]: AdminRoleForResponseType }, currentValue: AdminRole ) => ({ ...previousValue, [currentValue._id.toString()]: { name: currentValue.name, id: currentValue._id.toString(), routerList: currentValue.routerList || [], operation: currentValue.operation || {}, apiList: currentValue.apiList || [] } }), {} ); } }