Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import { Injectable, Logger } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model, Types } from 'mongoose'; import { Industry, BusinessType, LegalEntityType, MarketSegment, } from '../../infrastructure/schemas/product-classification.schema'; @Injectable() export class IndustryBusinessService { private readonly logger = new Logger(IndustryBusinessService.name); constructor( @InjectModel(Industry.name) private readonly indModel: Model<Industry>, @InjectModel(BusinessType.name) private readonly bizModel: Model<BusinessType>, @InjectModel(LegalEntityType.name) private readonly legalModel: Model<LegalEntityType>, @InjectModel(MarketSegment.name) private readonly segModel: Model<MarketSegment>, ) {} async listIndustries(): Promise<any[]> { return this.indModel .find({ active: true }) .sort({ industryName: 1 }) .lean() .exec(); } async bulkUpsertIndustries(industries: any[]): Promise<number> { const ops = industries.map((i) => ({ updateOne: { filter: { industryCode: i.industryCode }, update: { $set: i, $setOnInsert: { systemManaged: true } }, upsert: true, }, })); const result = await this.indModel.bulkWrite(ops, { ordered: false }); return result.upsertedCount + result.modifiedCount; } async listBusinessTypes(countryCode: string): Promise<any[]> { return this.bizModel .find({ countryCode, active: true }) .sort({ businessTypeName: 1 }) .lean() .exec(); } async listLegalEntityTypes(countryCode: string): Promise<any[]> { return this.legalModel .find({ countryCode, active: true }) .sort({ entityTypeName: 1 }) .lean() .exec(); } async listSegments(): Promise<any[]> { return this.segModel .find({ active: true }) .sort({ segmentCode: 1 }) .lean() .exec(); } } |