import { Injectable } from '@nestjs/common'; import { In, Repository } from 'typeorm'; import { DashboardPageData } from '../entity/dashboard_page_data.entity'; import { WidgetMaster } from '../entity/widget_master.entity'; import { InjectRepository } from '@nestjs/typeorm'; @Injectable() export class DashboardRepository { constructor( @InjectRepository(DashboardPageData) private readonly dashboardPageDataRepo: Repository, @InjectRepository(WidgetMaster) private readonly widgetMasterRepo: Repository, ) {} async getPages(mapped_entity_type: string, loggedInUser: any) { return await this.dashboardPageDataRepo.find({ where: { mapped_entity_type, applicable_type: loggedInUser.level_type, applicable_id: loggedInUser.level_id, enterprise_id: loggedInUser.enterprise_id, } }); } async getDashboardPageData( pageId: number ): Promise { return await this.dashboardPageDataRepo.findOne({ where: { id: pageId } }); } async getWidgetsByIds( widgetIds: number[], enterprise_id: number, ): Promise { if (!widgetIds.length) return []; return await this.widgetMasterRepo.find({ where: { id: In(widgetIds), enterprise_id: enterprise_id, } }); } }