chore(services): let `getAll`: always return `Model[]`

This commit is contained in:
WofWca 2023-03-02 17:13:14 +04:00 committed by kolaente
parent 5f9485414b
commit 6aa02e29b1
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 2 additions and 5 deletions

View File

@ -311,7 +311,7 @@ export default abstract class AbstractService<Model extends IAbstract = IAbstrac
* @param params Optional query parameters
* @param page The page to get
*/
async getAll(model : Model = new AbstractModel({}), params = {}, page = 1) {
async getAll(model : Model = new AbstractModel({}), params = {}, page = 1): Promise<Model[]> {
if (this.paths.getAll === '') {
throw new Error('This model is not able to get data.')
}
@ -331,10 +331,7 @@ export default abstract class AbstractService<Model extends IAbstract = IAbstrac
return []
}
if (Array.isArray(response.data)) {
return response.data.map(entry => this.modelGetAllFactory(entry))
}
return this.modelGetAllFactory(response.data)
return response.data.map(entry => this.modelGetAllFactory(entry))
} finally {
cancel()
}