/** * @author songxiwen * @date 2020/12/10 13:54 */ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { BaseService } from '../../../base/base.service'; import { ThirdPartyPlatform } from '../model/third.party.platform'; import { MongoDBCollection } from '../../../constant'; import { ThirdPartyPlatformResponseType } from '../type/api.key.type'; @Injectable() export class ThirdPartyPlatformService extends BaseService { constructor( @InjectModel(MongoDBCollection.ThirdPartyPlatform) protected readonly model: Model ) { super(model); } async getThirdPartyPlatformMap(): Promise<{ [key: string]: ThirdPartyPlatformResponseType; }> { const thirdPartyPlatformList = await this.model.find(); const platformMap: { [key: string]: ThirdPartyPlatformResponseType; } = thirdPartyPlatformList.reduce( ( previousValue: { [key: string]: ThirdPartyPlatformResponseType }, currentValue ) => ({ ...previousValue, [currentValue._id.toString()]: { id: currentValue._id.toString(), name: currentValue.name, limit: currentValue.limit, cycle: currentValue.cycle, isEnabled: currentValue.isEnabled, createdAt: currentValue.createdAt, updatedAt: currentValue.updatedAt } }), {} ); return platformMap; } }