From 3693d0c0a5be8cc62090f754cd1da3cbdc7cf9d9 Mon Sep 17 00:00:00 2001 From: Kevin L'Hereec Date: Fri, 3 Jul 2026 15:43:54 +0200 Subject: [PATCH] refactor(base-model): remove unused instance methods save/delete/refresh and instance fields --- database/base_model.ts | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/database/base_model.ts b/database/base_model.ts index ef9894b..4466d56 100644 --- a/database/base_model.ts +++ b/database/base_model.ts @@ -11,10 +11,6 @@ import { getMongoDb } from '#providers/mongodb_provider' export abstract class BaseModel { static collectionName: string - _id?: ObjectId - createdAt?: Date - updatedAt?: Date - static getDb(): Db { return getMongoDb() } @@ -110,37 +106,4 @@ export abstract class BaseModel { return collection } - async save(): Promise { - const constructor = this.constructor as typeof BaseModel - const collection = constructor.getDb().collection(constructor.collectionName) - this.updatedAt = new Date() - if (!this.createdAt) { - this.createdAt = new Date() - } - const { _id, ...data } = this as any - if (_id) { - await collection.updateOne({ _id }, { $set: data }) - } else { - const result = await collection.insertOne(data) - this._id = result.insertedId - } - } - - async delete(): Promise { - const constructor = this.constructor as typeof BaseModel - const collection = constructor.getDb().collection(constructor.collectionName) - if (!this._id) return false - const result = await collection.deleteOne({ _id: this._id }) - return result.deletedCount === 1 - } - - async refresh(): Promise { - const constructor = this.constructor as typeof BaseModel - const collection = constructor.getDb().collection(constructor.collectionName) - if (!this._id) return - const doc = await collection.findOne({ _id: this._id }) - if (doc) { - Object.assign(this, doc) - } - } }