finished add default icon for scene

This commit is contained in:
faris Aljohari
2024-10-28 01:51:27 -05:00
parent 5539f5f52a
commit 86fb73ab8d
8 changed files with 70 additions and 4 deletions

View File

@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import { SceneIconRepository } from '@app/common/modules/scene/repositories';
import { SceneIconType } from '@app/common/constants/secne-icon-type.enum';
import { defaultSceneIcon } from '@app/common/constants/default.scene.icon';
@Injectable()
export class SceneIconSeeder {
constructor(private readonly sceneIconRepository: SceneIconRepository) {}
async createSceneDefaultIconIfNotFound(): Promise<void> {
try {
const defaultSceneIconData = await this.sceneIconRepository.find({
where: { iconType: SceneIconType.Default },
});
if (defaultSceneIconData.length <= 0) {
console.log('Creating default scene icon...');
await this.createDefaultSceneIcon();
}
} catch (err) {
console.error('Error while checking default scene icon:', err);
throw err;
}
}
private async createDefaultSceneIcon(): Promise<void> {
try {
await this.sceneIconRepository.save({
icon: defaultSceneIcon,
iconType: SceneIconType.Default,
});
} catch (err) {
console.error('Error while creating default scene icon:', err);
throw err;
}
}
}