/** * @author songxiwen * @date 2020/10/15 14:06 */ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { BaseService } from '../../../base/base.service'; import { IconStyle } from '../model/icon.style'; import { MongoDBCollection } from '../../../constant'; import { IconStyleType } from './type/icon.type'; @Injectable() export class IconStyleService extends BaseService { constructor( @InjectModel(MongoDBCollection.IconStyle) protected readonly model: Model ) { super(model); } async getIconStyleMap(): Promise<{ [key: string]: IconStyleType }> { const iconStyleList = await this.model.find(); return iconStyleList.reduce( ( previousValue: { [key: string]: IconStyleType }, currentValue: IconStyle ) => ({ ...previousValue, [currentValue._id.toString()]: { id: currentValue._id.toString(), name: currentValue.name, updatedAt: currentValue.updatedAt, createdAt: currentValue.createdAt, isEnabled: currentValue.isEnabled } }), {} ); } }