mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
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;
|
|
}
|
|
}
|
|
}
|