localization, assign data-base, tenant domain, plan and subscription and data-base connection screen added
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { TRANSLATION_ENDPOINTS } from './translation.endpoints';
|
||||
import {
|
||||
CreateTranslationRequest,
|
||||
DataTableResponse,
|
||||
TranslationDataTableDto,
|
||||
TranslationDto,
|
||||
TranslationFilterParams,
|
||||
TranslationLookupDto,
|
||||
UpdateTranslationRequest
|
||||
} from '../models/translation.model';
|
||||
import {
|
||||
DataTableQuery,
|
||||
DataTableResult
|
||||
} from '../../../../shared/components/data-table/data-table.types';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TranslationService {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
createTranslation(request: CreateTranslationRequest): Observable<TranslationDto> {
|
||||
return this.http.post<TranslationDto>(TRANSLATION_ENDPOINTS.create, request);
|
||||
}
|
||||
|
||||
updateTranslation(id: string, request: UpdateTranslationRequest): Observable<TranslationDto> {
|
||||
return this.http.put<TranslationDto>(TRANSLATION_ENDPOINTS.update(id), request);
|
||||
}
|
||||
|
||||
getTranslationById(id: string): Observable<TranslationDto> {
|
||||
return this.http.get<TranslationDto>(TRANSLATION_ENDPOINTS.getById(id));
|
||||
}
|
||||
|
||||
autocomplete(options?: {
|
||||
translationKeyId?: string | null;
|
||||
languageId?: string | null;
|
||||
tenantId?: string | null;
|
||||
globalOnly?: boolean | null;
|
||||
term?: string | null;
|
||||
limit?: number;
|
||||
}): Observable<readonly TranslationLookupDto[]> {
|
||||
let params = new HttpParams();
|
||||
|
||||
if (options?.translationKeyId) {
|
||||
params = params.set('translationKeyId', options.translationKeyId);
|
||||
}
|
||||
if (options?.languageId) {
|
||||
params = params.set('languageId', options.languageId);
|
||||
}
|
||||
if (options?.tenantId) {
|
||||
params = params.set('tenantId', options.tenantId);
|
||||
}
|
||||
if (options?.globalOnly !== undefined && options?.globalOnly !== null) {
|
||||
params = params.set('globalOnly', options.globalOnly.toString());
|
||||
}
|
||||
if (options?.term) {
|
||||
params = params.set('term', options.term.trim());
|
||||
}
|
||||
if (options?.limit !== undefined && options?.limit !== null) {
|
||||
params = params.set('limit', options.limit);
|
||||
} else {
|
||||
params = params.set('limit', 10);
|
||||
}
|
||||
|
||||
return this.http.get<readonly TranslationLookupDto[]>(
|
||||
TRANSLATION_ENDPOINTS.autocomplete,
|
||||
{ params }
|
||||
);
|
||||
}
|
||||
|
||||
getTranslationDataTable(
|
||||
query: DataTableQuery,
|
||||
filters?: TranslationFilterParams
|
||||
): Observable<DataTableResult<TranslationDataTableDto>> {
|
||||
let params = new HttpParams();
|
||||
|
||||
if (filters?.translationKeyId) {
|
||||
params = params.set('translationKeyId', filters.translationKeyId);
|
||||
}
|
||||
if (filters?.languageId) {
|
||||
params = params.set('languageId', filters.languageId);
|
||||
}
|
||||
if (filters?.tenantId) {
|
||||
params = params.set('tenantId', filters.tenantId);
|
||||
}
|
||||
|
||||
params = params.set('globalOnly', (filters?.globalOnly ?? false).toString());
|
||||
|
||||
if (filters?.isApproved !== undefined && filters?.isApproved !== null) {
|
||||
params = params.set('isApproved', filters.isApproved.toString());
|
||||
}
|
||||
|
||||
return this.http
|
||||
.post<DataTableResponse<TranslationDataTableDto>>(
|
||||
TRANSLATION_ENDPOINTS.dataTable,
|
||||
query,
|
||||
{ params }
|
||||
)
|
||||
.pipe(
|
||||
map(response => ({
|
||||
draw: response.draw ?? query.draw,
|
||||
total: response.total ?? response.recordsTotal ?? 0,
|
||||
filtered: response.filtered ?? response.recordsFiltered ?? response.total ?? response.recordsTotal ?? 0,
|
||||
rows: response.rows ?? response.data ?? []
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user