feat: Upgrade template based on projects made with it
Some checks failed
Build, check & Test / run (push) Failing after 42s

Signed-off-by: Florian Bouillon <f.bouillon@aptatio.com>
This commit is contained in:
2023-10-09 11:47:11 +02:00
parent bf06e41238
commit e26b4eb4a5
42 changed files with 934 additions and 136 deletions

View File

@ -11,7 +11,7 @@ export default abstract class Dao<Object extends { id: any } = { id: any }> {
* @param obj the object to create
* @returns the object with it's id filled if create or null otherwise
*/
abstract create(obj: Omit<Object, 'id'>): Promise<Object | null>
abstract create(obj: Omit<Object, 'id' | 'created' | 'updated'>): Promise<Object | null>
/**
* insert a new object into the source
@ -81,12 +81,24 @@ export default abstract class Dao<Object extends { id: any } = { id: any }> {
*/
abstract update(obj: Object): Promise<Object | null>
/**
* change some elements from the object and return the object updated
* @param id the id of the object
* @param changegs the change to make
*/
public async patch(id: string, changes: Partial<Object>): Promise<Object | null> {
const query = await this.findById(id)
if (!query) {
return null
}
return await this.update({...query, ...changes})
}
/**
* update the remote reference of the object or create it if not found
* @param obj the object to update/insert
* @returns the object is updated/inserted or null otherwise
*/
public async upsert(object: Object | Omit<Object, 'id'>): Promise<Object | null> {
public async upsert(object: Object | Omit<Object, 'id' | 'created' | 'updated'>): Promise<Object | null> {
if ('id' in object) {
return this.update(object)
}