130 lines
2.8 KiB
TypeScript
130 lines
2.8 KiB
TypeScript
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
|
* @license PROPRIETARY (see license file)
|
|
*/
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { SessionService } from 'common/service';
|
|
import { GenderResource, Gender, UUID } from 'app/back-api';
|
|
import { RESTConfig } from 'app/back-api/rest-tools';
|
|
import { DataStore } from 'common/utils/data-store';
|
|
import { environment } from 'environments/environment';
|
|
import { GenericDataService } from './GenericDataService';
|
|
|
|
export interface MessageLogIn {
|
|
id: number;
|
|
name: string;
|
|
description: string;
|
|
}
|
|
|
|
@Injectable()
|
|
export class GenderService extends GenericDataService<Gender> {
|
|
|
|
getRestConfig(): RESTConfig {
|
|
return {
|
|
server: environment.server.karusic,
|
|
token: this.session.getToken()
|
|
}
|
|
}
|
|
private lambdaGets(): Promise<Gender[]> {
|
|
return GenderResource.gets({ restConfig: this.getRestConfig() });
|
|
}
|
|
|
|
constructor(private session: SessionService) {
|
|
super();
|
|
const self = this;
|
|
this.setStore(new DataStore<Gender>(() => this.lambdaGets()));
|
|
}
|
|
insert(data: Gender): Promise<Gender> {
|
|
const self = this;
|
|
return new Promise((resolve, reject) => {
|
|
GenderResource.post({
|
|
restConfig: this.getRestConfig(),
|
|
data
|
|
}).then((value: Gender) => {
|
|
self.dataStore.updateValue(value);
|
|
resolve(value);
|
|
}).catch((error) => {
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
patch(id: number, data: Gender): Promise<Gender> {
|
|
const self = this;
|
|
return new Promise((resolve, reject) => {
|
|
GenderResource.patch({
|
|
restConfig: this.getRestConfig(),
|
|
params: {
|
|
id
|
|
},
|
|
data
|
|
}).then((value: Gender) => {
|
|
self.dataStore.updateValue(value);
|
|
resolve(value);
|
|
}).catch((error) => {
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
delete(id: number): Promise<void> {
|
|
const self = this;
|
|
return new Promise((resolve, reject) => {
|
|
GenderResource.remove({
|
|
restConfig: this.getRestConfig(),
|
|
params: {
|
|
id
|
|
}
|
|
}).then(() => {
|
|
self.dataStore.delete(id);
|
|
resolve();
|
|
}).catch((error) => {
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
deleteCover(id: number, coverId: UUID): Promise<Gender> {
|
|
let self = this;
|
|
return new Promise((resolve, reject) => {
|
|
GenderResource.removeCover({
|
|
restConfig: this.getRestConfig(),
|
|
params: {
|
|
id,
|
|
coverId
|
|
}
|
|
}).then((value) => {
|
|
self.dataStore.updateValue(value);
|
|
resolve(value);
|
|
}).catch((error) => {
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
uploadCover(id: number,
|
|
file: File,
|
|
progress: any = null): Promise<Gender> {
|
|
let self = this;
|
|
return new Promise((resolve, reject) => {
|
|
GenderResource.uploadCover({
|
|
restConfig: this.getRestConfig(),
|
|
params: {
|
|
id,
|
|
},
|
|
data: {
|
|
file,
|
|
fileName: file.name
|
|
}
|
|
}).then((value) => {
|
|
self.dataStore.updateValue(value);
|
|
resolve(value);
|
|
}).catch((error) => {
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|