fix: unhance migration logic

This commit is contained in:
yassinedorbozgithub
2025-01-04 10:00:29 +01:00
parent a1765b647b
commit e0d2388e95
3 changed files with 53 additions and 44 deletions

View File

@@ -19,18 +19,10 @@ export class MetadataService {
private readonly metadataModel: Model<Metadata>,
) {}
async createMetadata(dto: Partial<Metadata>) {
return await this.metadataModel.create(dto);
}
async findOrCreate(dto: Partial<Metadata>) {
const metadata = await this.metadataModel.findOne({ name: dto.name });
if (metadata) {
await this.setMetadata(dto.name, dto.value);
} else {
await this.createMetadata(dto);
}
async createOrUpdate(dto: Metadata) {
return await this.metadataModel.findOneAndUpdate({ name: dto.name }, dto, {
upsert: true,
});
}
async getMetadata(name: string) {