mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: unhance migration logic
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user