??
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
import { Moment } from 'moment';
|
||||
|
||||
import { Deserializable } from './deserializable.model';
|
||||
import { Serializable } from './serializable.model';
|
||||
import * as moment from 'moment';
|
||||
import { User } from './user.model';
|
||||
|
||||
export class Base implements Deserializable, Serializable {
|
||||
id?: string;
|
||||
createdAt?: Moment;
|
||||
modifiedAt?: Moment;
|
||||
createdById?: string;
|
||||
modifiedById?: string;
|
||||
createdBy?: User;
|
||||
modifiedBy?: User;
|
||||
|
||||
constructor(data: Partial<Base> = {}) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deserialize(input: any): this {
|
||||
if (input.createdAt) { input.createdAt = moment(input.createdAt).utc(true); }
|
||||
if (input.modifiedAt) { input.modifiedAt = moment(input.modifiedAt).utc(true); }
|
||||
if (input.createdBy) { input.createdBy = new User(input.createdBy); }
|
||||
if (input.modifiedBy) { input.modifiedBy = new User(input.modifiedBy); }
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serialize() : any {
|
||||
return Object.assign({}, this);
|
||||
}
|
||||
import { Moment } from 'moment';
|
||||
|
||||
import { Deserializable } from './deserializable.model';
|
||||
import { Serializable } from './serializable.model';
|
||||
import * as moment from 'moment';
|
||||
import { User } from './user.model';
|
||||
|
||||
export class Base implements Deserializable, Serializable {
|
||||
id?: string;
|
||||
createdAt?: Moment;
|
||||
modifiedAt?: Moment;
|
||||
createdById?: string;
|
||||
modifiedById?: string;
|
||||
createdBy?: User;
|
||||
modifiedBy?: User;
|
||||
|
||||
constructor(data: Partial<Base> = {}) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deserialize(input: any): this {
|
||||
if (input.createdAt) { input.createdAt = moment(input.createdAt).utc(true); }
|
||||
if (input.modifiedAt) { input.modifiedAt = moment(input.modifiedAt).utc(true); }
|
||||
if (input.createdBy) { input.createdBy = new User(input.createdBy); }
|
||||
if (input.modifiedBy) { input.modifiedBy = new User(input.modifiedBy); }
|
||||
Object.assign(this, input);
|
||||
return this;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serialize() : any {
|
||||
return Object.assign({}, this);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Deserializable {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deserialize(input: any): this;
|
||||
export interface Deserializable {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
deserialize(input: any): this;
|
||||
}
|
||||
@@ -1,124 +1,124 @@
|
||||
import { Base } from './base.model';
|
||||
import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { map } from 'rxjs';
|
||||
import { Record } from 'src/app/models/record.model';
|
||||
|
||||
export class Layer extends Base {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
number?: Number;
|
||||
source?: string;
|
||||
name?: string;
|
||||
records: Record[] = [];
|
||||
created?: string;
|
||||
|
||||
constructor(data: Partial<Layer> = {}) {
|
||||
super();
|
||||
Object.assign(this, data);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
override deserialize(input: any): this {
|
||||
Object.assign(this, Object.assign(this, super.deserialize(input)));
|
||||
if (this.records) { this.records = this.records.map(x => new Record().deserialize(x)); }
|
||||
return this;
|
||||
}
|
||||
override serialize() {
|
||||
this.number = 0; // will be overrided in backend
|
||||
return Object.assign({}, this);
|
||||
}
|
||||
static getForm(fb: UntypedFormBuilder) {
|
||||
return fb.group({
|
||||
id: [null],
|
||||
name: ['', Validators.required],
|
||||
source: ['', Validators.required],
|
||||
sheetId: '1G_Hu8DTP-PSPNXTaVYhc_ppnTQi6HWoA4oXSSdUmM9E',
|
||||
createdAt: '',
|
||||
modifiedAt: '',
|
||||
createdBy: '',
|
||||
modifiedBy: '',
|
||||
modified: '',
|
||||
created: ''
|
||||
});
|
||||
}
|
||||
fillForm(form: UntypedFormGroup) {
|
||||
form.patchValue(this);
|
||||
form.patchValue({
|
||||
createdBy: this.createdBy?.userName,
|
||||
modifiedBy: this.modifiedBy?.userName
|
||||
});
|
||||
}
|
||||
loadForm(form: UntypedFormGroup) {
|
||||
for (const field of Object.keys(form.controls)) {
|
||||
this[field as keyof Layer] = form.controls[field].value;
|
||||
}
|
||||
this.createdBy = undefined;
|
||||
this.modifiedBy = undefined;
|
||||
}
|
||||
//API Actions
|
||||
static add(input: Layer, _http: HttpClient): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.post<string>(`${environment.api.url}/layers`, { ...input.serialize(), }).subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
static getList(_http: HttpClient): any {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<Layer[]>(`${environment.api.url}/layers`)
|
||||
.pipe(map(data => data.map(x => new Layer().deserialize(x))))
|
||||
.subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
});
|
||||
}
|
||||
static getById(id: string, _http: HttpClient): Promise<Layer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<Layer>(`${environment.api.url}/layers/${id}`).pipe(map(x => new Layer().deserialize(x))).subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
});
|
||||
}
|
||||
static parseFile(file: File, _http: HttpClient): Promise<Layer[]> {
|
||||
const formData = new FormData();
|
||||
formData.append(file.name, file);
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.post<Layer[]>(`${environment.api.url}/layers/parseFile`, formData,
|
||||
).pipe(map(data => data.map(x => new Layer().deserialize(x))))
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise<Layer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<Layer>(`${environment.api.url}/layers/parseGoogleSheet/${sheetId}`,
|
||||
).pipe(map(data => new Layer().deserialize(data)))
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
static exportToGoogleSheet(id: string, _http: HttpClient): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<boolean>(`${environment.api.url}/layers/exportToGoogleSheet/${id}`,
|
||||
).subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
import { Base } from './base.model';
|
||||
import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { map } from 'rxjs';
|
||||
import { Record } from 'src/app/models/record.model';
|
||||
|
||||
export class Layer extends Base {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
number?: Number;
|
||||
source?: string;
|
||||
name?: string;
|
||||
records: Record[] = [];
|
||||
created?: string;
|
||||
|
||||
constructor(data: Partial<Layer> = {}) {
|
||||
super();
|
||||
Object.assign(this, data);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
override deserialize(input: any): this {
|
||||
Object.assign(this, Object.assign(this, super.deserialize(input)));
|
||||
if (this.records) { this.records = this.records.map(x => new Record().deserialize(x)); }
|
||||
return this;
|
||||
}
|
||||
override serialize() {
|
||||
this.number = 0; // will be overrided in backend
|
||||
return Object.assign({}, this);
|
||||
}
|
||||
static getForm(fb: UntypedFormBuilder) {
|
||||
return fb.group({
|
||||
id: [null],
|
||||
name: ['', Validators.required],
|
||||
source: ['', Validators.required],
|
||||
sheetId: '1G_Hu8DTP-PSPNXTaVYhc_ppnTQi6HWoA4oXSSdUmM9E',
|
||||
createdAt: '',
|
||||
modifiedAt: '',
|
||||
createdBy: '',
|
||||
modifiedBy: '',
|
||||
modified: '',
|
||||
created: ''
|
||||
});
|
||||
}
|
||||
fillForm(form: UntypedFormGroup) {
|
||||
form.patchValue(this);
|
||||
form.patchValue({
|
||||
createdBy: this.createdBy?.userName,
|
||||
modifiedBy: this.modifiedBy?.userName
|
||||
});
|
||||
}
|
||||
loadForm(form: UntypedFormGroup) {
|
||||
for (const field of Object.keys(form.controls)) {
|
||||
this[field as keyof Layer] = form.controls[field].value;
|
||||
}
|
||||
this.createdBy = undefined;
|
||||
this.modifiedBy = undefined;
|
||||
}
|
||||
//API Actions
|
||||
static add(input: Layer, _http: HttpClient): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.post<string>(`${environment.api.url}/layers`, { ...input.serialize(), }).subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
static getList(_http: HttpClient): any {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<Layer[]>(`${environment.api.url}/layers`)
|
||||
.pipe(map(data => data.map(x => new Layer().deserialize(x))))
|
||||
.subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
});
|
||||
}
|
||||
static getById(id: string, _http: HttpClient): Promise<Layer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<Layer>(`${environment.api.url}/layers/${id}`).pipe(map(x => new Layer().deserialize(x))).subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
});
|
||||
}
|
||||
static parseFile(file: File, _http: HttpClient): Promise<Layer[]> {
|
||||
const formData = new FormData();
|
||||
formData.append(file.name, file);
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.post<Layer[]>(`${environment.api.url}/layers/parseFile`, formData,
|
||||
).pipe(map(data => data.map(x => new Layer().deserialize(x))))
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise<Layer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<Layer>(`${environment.api.url}/layers/parseGoogleSheet/${sheetId}`,
|
||||
).pipe(map(data => new Layer().deserialize(data)))
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
static exportToGoogleSheet(id: string, _http: HttpClient): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.get<boolean>(`${environment.api.url}/layers/exportToGoogleSheet/${id}`,
|
||||
).subscribe({
|
||||
next: (data) => {
|
||||
resolve(data);
|
||||
},
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
import { Base } from './base.model';
|
||||
|
||||
export class Record extends Base {
|
||||
code?: string;
|
||||
value?: number;
|
||||
desc1?: string;
|
||||
desc2?: string;
|
||||
desc3?: string;
|
||||
desc4?: string;
|
||||
desc5?: string;
|
||||
|
||||
constructor(data: Partial<Record> = {}) {
|
||||
super();
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
override deserialize(input: any): this {
|
||||
Object.assign(this, Object.assign(this, super.deserialize(input)));
|
||||
return this;
|
||||
}
|
||||
import { Base } from './base.model';
|
||||
|
||||
export class Record extends Base {
|
||||
code?: string;
|
||||
value?: number;
|
||||
desc1?: string;
|
||||
desc2?: string;
|
||||
desc3?: string;
|
||||
desc4?: string;
|
||||
desc5?: string;
|
||||
|
||||
constructor(data: Partial<Record> = {}) {
|
||||
super();
|
||||
Object.assign(this, data);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
override deserialize(input: any): this {
|
||||
Object.assign(this, Object.assign(this, super.deserialize(input)));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Serializable {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serialize(input: this): any;
|
||||
export interface Serializable {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serialize(input: this): any;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
export class User {
|
||||
id!: string;
|
||||
email!: string;
|
||||
userName!: string;
|
||||
googleCredentials!: string;
|
||||
avatar?: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
constructor(input: any) {
|
||||
Object.assign(this, input)
|
||||
}
|
||||
export class User {
|
||||
id!: string;
|
||||
email!: string;
|
||||
userName!: string;
|
||||
googleCredentials!: string;
|
||||
avatar?: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
constructor(input: any) {
|
||||
Object.assign(this, input)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user