feat: Allow a user to filters elements on the API (#275)

This commit is contained in:
2024-10-10 14:56:11 +02:00
committed by GitHub
parent f2621890e1
commit bf54ab3809
28 changed files with 1429 additions and 126 deletions

28
src/models/Model.ts Normal file
View File

@@ -0,0 +1,28 @@
import { objectLoop } from '@dzeio/object-util'
import type TCGdex from '../tcgdex'
export default abstract class Model {
public constructor(
protected readonly sdk: TCGdex
) { }
/**
* build a model depending on the data given
* @param model the model to build
* @param data the data to fill it with
*/
public static build<T extends Model>(model: T, data?: object): T {
if (!data) {
throw new Error('data is necessary.')
}
model.fill(data)
return model
}
protected fill(obj: object) {
objectLoop(obj, (value, key) => {
(this as object)[key] = value
})
}
}