/** * @author songxiwen * @date 2020/10/12 16:30 */ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { BaseService } from '../../../base/base.service'; import { Icon } from '../model/icon'; import { MongoDBCollection } from '../../../constant'; import { IconType } from './type/icon.type'; @Injectable() export class IconService extends BaseService { constructor( @InjectModel(MongoDBCollection.Icon) protected readonly model: Model ) { super(model); } async getIconMap(): Promise<{ [key: string]: IconType }> { const categoryList = await this.model.find(); return categoryList.reduce( (previousValue: { [key: string]: IconType }, currentValue: Icon) => ({ ...previousValue, [currentValue._id.toString()]: { id: currentValue._id.toString(), name: currentValue.name, updatedAt: currentValue.updatedAt, createdAt: currentValue.createdAt, fileKey: currentValue.fileKey, kitId: currentValue.kitId, kitCategoryId: currentValue.kitCategoryId, width: currentValue.width || 0, height: currentValue.height || 0, size: currentValue.size || 0 } }), {} ); } }