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 | import { Injectable, Logger } from '@nestjs/common'; import { Connection } from 'mongoose'; import { InjectConnection } from '@nestjs/mongoose'; @Injectable() export class SeedValidationService { private readonly logger = new Logger(SeedValidationService.name); constructor(@InjectConnection() private readonly connection: Connection) {} async validateSeededData(): Promise<{ success: boolean; warnings: string[]; }> { this.logger.log('Starting seed verification checks...'); const warnings: string[] = []; const collections = this.connection.collections; // Check that at least countries and currencies exist if (collections['mdm_countries']) { const countryCount = await collections['mdm_countries'].countDocuments(); if (countryCount === 0) warnings.push('mdm_countries collection is empty!'); } if (collections['mdm_currencies']) { const currencyCount = await collections['mdm_currencies'].countDocuments(); if (currencyCount === 0) warnings.push('mdm_currencies collection is empty!'); } const success = warnings.length === 0; if (success) { this.logger.log('Seeded data validation passed successfully.'); } else { this.logger.warn( `Verification checks finished with warnings: ${warnings.join(', ')}`, ); } return { success, warnings }; } } |