1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-23 23:07:46 +01:00

feat: Cambiato Model da javel a Coloquent per interfacciamento facilitato con JSON API

Coloquent: https://github.com/DavidDuwaer/Coloquent
This commit is contained in:
Maicol Battistini 2021-10-08 10:53:56 +02:00
parent 965e1cb2f3
commit 08ac9b3f16
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
2 changed files with 11 additions and 20 deletions

View File

@ -40,7 +40,7 @@
"async-wait-until": "^2.0.7", "async-wait-until": "^2.0.7",
"classnames": "^2.3.1", "classnames": "^2.3.1",
"collect.js": "^4.29.0", "collect.js": "^4.29.0",
"javel": "^0.1.7", "coloquent": "^2.4.0",
"jquery": "^3.6.0", "jquery": "^3.6.0",
"lit": "^2.0.0", "lit": "^2.0.0",
"locale-code": "^2.0.2", "locale-code": "^2.0.2",

View File

@ -1,28 +1,19 @@
import BaseModel from 'javel'; import {Model as BaseModel, PluralResponse} from 'coloquent';
import {snakeCase} from 'lodash'; import {snakeCase} from 'lodash';
import redaxios from 'redaxios';
export default class Model extends BaseModel { export default class Model extends BaseModel {
urlPath: string; /**
* Just an alias to the get() method
*/
static all(): Promise<PluralResponse<InstanceType<Model>>> {
return this.get();
}
baseUrl(): string { getJsonApiBaseUrl(): string {
return '/api'; return '/api';
} }
buildUrl({params}): Array { getJsonApiType(): string {
return [this.urlPath ?? snakeCase(this.constructor.name), ...params]; return (super.getJsonApiType() ?? snakeCase(this.constructor.name));
}
makeRequest({
method, url, data, query
}: {
method: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'head' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD',
url: string,
data: any,
query: {...}
}): Promise {
return redaxios({
method, url, data, params: query
});
} }
} }