@ -4,7 +4,6 @@
|
||||
* you MUST call it through the `DaoFactory` file
|
||||
*/
|
||||
export default abstract class Dao<Object extends { id: any } = { id: any }> {
|
||||
|
||||
/**
|
||||
* insert a new object into the source
|
||||
*
|
||||
@ -19,7 +18,8 @@ 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
|
||||
*/
|
||||
public insert: Dao<Object>['create'] = (obj: Parameters<Dao<Object>['create']>[0]) => this.create(obj)
|
||||
public insert: Dao<Object>['create'] = (obj: Parameters<Dao<Object>['create']>[0]) =>
|
||||
this.create(obj)
|
||||
|
||||
/**
|
||||
* find the list of objects having elements from the query
|
||||
@ -35,7 +35,8 @@ export default abstract class Dao<Object extends { id: any } = { id: any }> {
|
||||
* @param query a partial object which filter depending on the elements, if not set it will fetch everything
|
||||
* @returns an array containing the list of elements that match with the query
|
||||
*/
|
||||
public find: Dao<Object>['findAll'] = (query: Parameters<Dao<Object>['findAll']>[0]) => this.findAll(query)
|
||||
public find: Dao<Object>['findAll'] = (query: Parameters<Dao<Object>['findAll']>[0]) =>
|
||||
this.findAll(query)
|
||||
|
||||
/**
|
||||
* find an object by it's id
|
||||
@ -46,7 +47,7 @@ export default abstract class Dao<Object extends { id: any } = { id: any }> {
|
||||
* @returns
|
||||
*/
|
||||
public findById(id: Object['id']): Promise<Object | null> {
|
||||
return this.findOne({id: id} as Partial<Object>)
|
||||
return this.findOne({ id: id } as Partial<Object>)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,14 +92,16 @@ export default abstract class Dao<Object extends { id: any } = { id: any }> {
|
||||
if (!query) {
|
||||
return null
|
||||
}
|
||||
return await this.update({...query, ...changes})
|
||||
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' | 'created' | 'updated'>): Promise<Object | null> {
|
||||
public async upsert(
|
||||
object: Object | Omit<Object, 'id' | 'created' | 'updated'>
|
||||
): Promise<Object | null> {
|
||||
if ('id' in object) {
|
||||
return this.update(object)
|
||||
}
|
||||
|
@ -9,8 +9,7 @@
|
||||
*
|
||||
* Touch this interface to define which key is linked to which Dao
|
||||
*/
|
||||
interface DaoItem {
|
||||
}
|
||||
interface DaoItem {}
|
||||
|
||||
/**
|
||||
* Class to get any DAO
|
||||
@ -48,7 +47,8 @@ export default class DaoFactory {
|
||||
*/
|
||||
private static initDao(item: keyof DaoItem): any | undefined {
|
||||
switch (item) {
|
||||
default: return undefined
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user