commit 2f271b21a216f773713329d562ad9cc90868af9a Author: Hadi Khazaee Asl Date: Fri Apr 17 16:22:31 2026 +0330 Initial Commit ... diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..59d9a3a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# Editor configuration, see https://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.ts] +quote_type = single + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a353369 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp +/out-tsc +# Only exists if Bazel was run +/bazel-out + +# dependencies +/node_modules + +# profiling files +chrome-profiler-events*.json + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history/* + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +yarn-error.log +testem.log +/typings + +# System Files +.DS_Store +Thumbs.db + +# +documentation +package-lock.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..87e18d4 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# XSaherElmApiSDK + +this is a library which provides all access to Api. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/angular.json b/angular.json new file mode 100644 index 0000000..585d2c4 --- /dev/null +++ b/angular.json @@ -0,0 +1,45 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "cli": { + "analytics": false + }, + "version": 1, + "newProjectRoot": "projects", + "projects": { + "x-saherelm-api-sdk": { + "projectType": "library", + "root": "projects/x-saherelm-api-sdk", + "sourceRoot": "projects/x-saherelm-api-sdk/src", + "prefix": "lib", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:ng-packagr", + "options": { + "project": "projects/x-saherelm-api-sdk/ng-package.json" + }, + "configurations": { + "production": { + "tsConfig": "projects/x-saherelm-api-sdk/tsconfig.lib.prod.json" + }, + "development": { + "tsConfig": "projects/x-saherelm-api-sdk/tsconfig.lib.json" + }, + "ivy": { + "tsConfig": "projects/x-saherelm-api-sdk/tsconfig.lib.ivy.json" + } + }, + "defaultConfiguration": "production" + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "projects/x-saherelm-api-sdk/src/test.ts", + "tsConfig": "projects/x-saherelm-api-sdk/tsconfig.spec.json", + "karmaConfig": "projects/x-saherelm-api-sdk/karma.conf.js" + } + } + } + } + }, + "defaultProject": "x-saherelm-api-sdk" +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..0457f57 --- /dev/null +++ b/package.json @@ -0,0 +1,77 @@ +{ + "name": "x-saherelm-api-sdkholder", + "version": "0.0.0", + "scripts": { + "ng": "ng", + "start": "ng serve", + "build": "ng build", + "refreshModule": "npm run cleanModule && npm i", + "watch": "ng build --watch --configuration development", + "build:ivy": "ng build x-saherelm-api-sdk --configuration=ivy", + "publishModule": "npm run buildModule && npm run packModule", + "buildModule": "npm run preBuildModule && ng build x-saherelm-api-sdk", + "serveDocs": "compodoc -p projects/x-saherelm-api-sdk/tsconfig.lib.json --theme material -s", + "packModule": "cd dist/x-saherelm-api-sdk && npm pack && shx mv *.tgz ../../../../Documents/pack", + "unpublishModuleFromRegistry": "npm unpublish --force x-saherelm-api-sdk --registry https://npm.saherelmhub.ir", + "publishModuleToRegistry": "npm publish ../../Documents/pack/x-saherelm-api-sdk-0.0.1.tgz --registry https://npm.saherelmhub.ir", + "rePublishModuleToRegistry": "npm run publishModule && npm run unpublishModuleFromRegistry && npm run publishModuleToRegistry", + "preBuildModule": "shx --silent rm -rf dist && shx --silent rm ../../Documents/pack/x-saherelm-api-sdk*.tgz || shx true && npm run prepareDependenciesFromRegistry", + "cleanModule": "shx true --silent rm -rf dist && shx true --silent rm ./package-lock.json && shx true --silent rm -rf node_modules && npm i --save-dev shx@0.3.2", + "prepareDependenciesFromRegistry": "npm i --force -D --registry https://npm.saherelmhub.ir x-framework-core x-framework-services x-framework-identity-sdk x-framework-push-service", + "generateDocs": "compodoc -p projects/x-saherelm-api-sdk/tsconfig.lib.json --theme material --hideGenerator --disableSourceCode --disableDomTree --disableTemplateTab --disableStyleTab --disablePrivate --disableLifeCycleHooks --disableRoutesGraph --disableCoverage --customFavicon ../../Documents/resources/favicon.png --customLogo ../../Documents/resources/favicon.png" + }, + "private": true, + "dependencies": { + "@angular/animations": "~12.0.4", + "@angular/common": "~12.0.4", + "@angular/compiler": "~12.0.4", + "@angular/core": "~12.0.4", + "@angular/forms": "~12.0.4", + "@angular/platform-browser": "~12.0.4", + "@angular/platform-browser-dynamic": "~12.0.4", + "@angular/router": "~12.0.4", + "rxjs": "~6.6.0", + "tslib": "^2.1.0", + "zone.js": "~0.11.4" + }, + "devDependencies": { + "@angular-devkit/build-angular": "~12.0.5", + "@angular/cdk": "^12.1.2", + "@angular/cli": "~12.0.4", + "@angular/compiler-cli": "~12.0.4", + "@angular/material": "^12.1.2", + "@angular/material-moment-adapter": "^12.1.2", + "@compodoc/compodoc": "^1.1.14", + "@ionic/angular": "^5.6.11", + "@microsoft/signalr": "^6.0.5", + "@microsoft/signalr-protocol-msgpack": "^7.0.2", + "@types/crypto-js": "^4.0.2", + "@types/howler": "^2.2.3", + "@types/jasmine": "~3.6.0", + "@types/node": "^12.11.1", + "@types/uuid": "^8.3.1", + "bignumber.js": "^9.0.2", + "crypto-js": "^4.0.0", + "howler": "^2.2.3", + "ionicons": "^5.5.2", + "jalali-moment": "^3.3.10", + "jasmine-core": "~3.7.0", + "karma": "~6.3.0", + "karma-chrome-launcher": "~3.1.0", + "karma-coverage": "~2.0.3", + "karma-jasmine": "~4.0.0", + "karma-jasmine-html-reporter": "^1.5.0", + "libphonenumber-js": "^1.9.22", + "md5-typescript": "^1.0.5", + "moment": "^2.29.1", + "ng-packagr": "^12.0.0", + "ngx-device-detector": "^2.1.1", + "shx": "^0.3.3", + "typescript": "~4.2.3", + "uuid": "^8.3.2", + "x-framework-core": "0.0.1", + "x-framework-identity-sdk": "0.0.1", + "x-framework-push-service": "0.0.1", + "x-framework-services": "0.0.1" + } +} diff --git a/projects/x-saherelm-api-sdk/README.md b/projects/x-saherelm-api-sdk/README.md new file mode 100644 index 0000000..0837b3d --- /dev/null +++ b/projects/x-saherelm-api-sdk/README.md @@ -0,0 +1,11 @@ +# XSaherElmApiSDK + +this is a library which provides all access to Api. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) \ No newline at end of file diff --git a/projects/x-saherelm-api-sdk/karma.conf.js b/projects/x-saherelm-api-sdk/karma.conf.js new file mode 100644 index 0000000..5214877 --- /dev/null +++ b/projects/x-saherelm-api-sdk/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, '../../coverage/x-mabsut-api-sdk'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/projects/x-saherelm-api-sdk/ng-package.json b/projects/x-saherelm-api-sdk/ng-package.json new file mode 100644 index 0000000..4a20290 --- /dev/null +++ b/projects/x-saherelm-api-sdk/ng-package.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/x-saherelm-api-sdk", + "lib": { + "entryFile": "src/public-api.ts" + } +} \ No newline at end of file diff --git a/projects/x-saherelm-api-sdk/package.json b/projects/x-saherelm-api-sdk/package.json new file mode 100644 index 0000000..857b7af --- /dev/null +++ b/projects/x-saherelm-api-sdk/package.json @@ -0,0 +1,22 @@ +{ + "name": "x-saherelm-api-sdk", + "version": "0.0.1", + "description": "provide API SDK of xSaherElm API", + "keywords": [ + "x-saherelm", + "x-saherelm-api-sdk" + ], + "homepage": "https://saherelm.ir", + "author": { + "name": "Hadi Khazaee Asl", + "email": "hadi_khazaee_asl@yahoo.com", + "url": "https://saherelm.ir" + }, + "peerDependencies": { + "@angular/common": "^12.0.4", + "@angular/core": "^12.0.4" + }, + "dependencies": { + "tslib": "^2.1.0" + } +} \ No newline at end of file diff --git a/projects/x-saherelm-api-sdk/src/lib/base/i-x-entity-actions.interface.ts b/projects/x-saherelm-api-sdk/src/lib/base/i-x-entity-actions.interface.ts new file mode 100644 index 0000000..59dab61 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/base/i-x-entity-actions.interface.ts @@ -0,0 +1,472 @@ +import { Observable } from 'rxjs'; +import { XBaseRangeRequestDto } from 'x-framework-core'; +import { HttpEvent, HttpResponse } from '@angular/common/http'; +import { XQueryDto, XQueryResultDto } from 'x-framework-identity-sdk'; + +export interface IXEntityActions { + // + //#region Repository Implementation ... + // + //#region Retrieve ... + // + //#region Get ... + /** + * Retrieve Specified Item based on Id + * + * @param id the Object ID ... + * @param containsDetail specify retrieve full details + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callGet( + id: TKey, + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callGet( + id: TKey, + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callGet( + id: TKey, + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callGet( + id: TKey, + containsDetail?: boolean, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region GetAll ... + /** + * Retrieve all Items + * + * @param containsDetail specify retrieve full details + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callGetAll( + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + callGetAll( + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + callGetAll( + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + callGetAll( + containsDetail?: boolean, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region FindOne ... + /** + * Fine first Item which matched to the query string + * + * @param query search pattern + * @param containsDetail specify retrieve full details + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callFindOne( + query: string, + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callFindOne( + query: string, + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callFindOne( + query: string, + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callFindOne( + query: string, + containsDetail?: boolean, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region FindMany ... + /** + * Find a Collection of items which matched to Specified Query string + * + * @param query search pattern + * @param containsDetail specify retrieve full details + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callFindMany( + query: string, + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + callFindMany( + query: string, + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + callFindMany( + query: string, + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + callFindMany( + query: string, + containsDetail?: boolean, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region Query ... + /** + * Retrieve Items based on XQuery model + * + * @param query specify data projection attributes + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callQuery( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + callQuery( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + callQuery( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + callQuery( + query: XQueryDto, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + //#endregion + + // + //#region Add ... + // + //#region Add ... + /** + * Add New Item + * + * @param body the new Content which requires to add + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callAdd( + body: TModel, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callAdd( + body: TModel, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callAdd( + body: TModel, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callAdd( + body: TModel, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region AddOrUpdate ... + /** + * Add New Item or Update Exists Item + * + * @param body hte instance of Entity + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region AddMany ... + /** + * Add a Collection of items + * + * @param body an instance of XBaseRangeRequest which contains a collection of items + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + //#endregion + + // + //#region Update ... + // + //#region Update ... + /** + * Update Specified Item + * + * @param body the instance with all changes + * @param id the Id of Object which are going to replace or update with this + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region UpdateMany ... + /** + * Update a Collection of Items + * + * @param body an instance of XBaseRangeRequestDto + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + //#endregion + + // + //#region Exists ... + /** + * Check an items is Exists or not + * + * @param id the id of item + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callIsExists( + id: TKey, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callIsExists( + id: TKey, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callIsExists( + id: TKey, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callIsExists( + id: TKey, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region Remove ... + // + //#region Remove ... + /** + * Remove Specified item by its ID + * + * @param id pointer to specific instance + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callRemove( + id: TKey, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callRemove( + id: TKey, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callRemove( + id: TKey, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callRemove( + id: TKey, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + + // + //#region RemoveMany ... + /** + * Remove a Collection of Items base on RangeRequest + * + * @param body an instance of XBaseRangeRequestDto + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: any, + reportProgress?: boolean + ): Observable; + //#endregion + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/base/x-base-entity.service.ts b/projects/x-saherelm-api-sdk/src/lib/base/x-base-entity.service.ts new file mode 100644 index 0000000..98462da --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/base/x-base-entity.service.ts @@ -0,0 +1,796 @@ +import { + XQueryDto, + XQueryResultDto, + XBaseApiService, +} from 'x-framework-identity-sdk'; +import { Observable } from 'rxjs'; +import { + XBaseEndPointAction, + XBaseEndPointParam, +} from '../typings/x-endpoint.typings'; +import { IXEntityActions } from './i-x-entity-actions.interface'; +import { HttpResponse, HttpEvent, HttpParams } from '@angular/common/http'; +import { applyConnectionIdToHeader } from '../typings/x-push-provider.typings'; +import { toXString, XBaseRangeRequestDto, XValidators } from 'x-framework-core'; + +export abstract class XBaseEntityService + extends XBaseApiService + implements IXEntityActions +{ + // + //#region Repository Implementation ... + // + //#region Retrieve ... + // + //#region Get ... + public callGet( + id: TKey, + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callGet( + id: TKey, + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callGet( + id: TKey, + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callGet( + id: TKey, + containsDetail?: boolean, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(id); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.Get); + + // + // Preparing HttpParams ... + let params: HttpParams = null; + if (!!containsDetail) { + params = this.addContainsDetailQueryParam(params, containsDetail); + } + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetAll ... + public callGetAll( + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callGetAll( + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callGetAll( + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callGetAll( + containsDetail?: boolean, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.GetAll); + + // + // Preparing HttpParams ... + let params: HttpParams = null; + if (!!containsDetail) { + params = this.addContainsDetailQueryParam(params, containsDetail); + } + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region FindOne ... + public callFindOne( + query: string, + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callFindOne( + query: string, + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callFindOne( + query: string, + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callFindOne( + query: string, + containsDetail?: boolean, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.FindOne, { + key: XBaseEndPointParam.XQuery, + value: query, + }); + + // + // Preparing HttpParams ... + let params: HttpParams = null; + if (!!containsDetail) { + params = this.addContainsDetailQueryParam(params, containsDetail); + } + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region FindMany ... + public callFindMany( + query: string, + containsDetail?: boolean, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callFindMany( + query: string, + containsDetail?: boolean, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callFindMany( + query: string, + containsDetail?: boolean, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callFindMany( + query: string, + containsDetail?: boolean, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.FindMany, { + key: XBaseEndPointParam.XQuery, + value: query, + }); + + // + // Preparing HttpParams ... + let params: HttpParams = null; + if (!!containsDetail) { + params = this.addContainsDetailQueryParam(params, containsDetail); + } + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Query ... + public callQuery( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public callQuery( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public callQuery( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public callQuery( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.Query); + + // + // Preparing HttpParams ... + const params: HttpParams = this.generateXQueryHttpParams(query); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Add ... + // + //#region Add ... + public callAdd( + body: TModel, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callAdd( + body: TModel, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callAdd( + body: TModel, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callAdd( + body: TModel, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(body); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.Add); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, body, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region AddOrUpdate ... + public callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callAddOrUpdate( + body: TModel, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callAddOrUpdate( + body: TModel, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(body); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.AddOrUpdate); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, body, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region AddMany ... + public callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callAddMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(body); + XValidators.validateHasChilds(body.items); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.AddMany); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, body, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Update ... + // + //#region Update ... + public callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callUpdate( + id: TKey, + body: TModel, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(id); + XValidators.validateNotNull(body); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.Update, { + key: XBaseEndPointParam.XId, + value: toXString(id), + }); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, body, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region UpdateMany ... + public callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callUpdateMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(body); + XValidators.validateHasChilds(body.items); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.UpdateMany); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, body, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Exists ... + public callIsExists( + id: TKey, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callIsExists( + id: TKey, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callIsExists( + id: TKey, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callIsExists( + id: TKey, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(id); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.IsExists, { + key: XBaseEndPointParam.XId, + value: toXString(id), + }); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region Remove ... + // + //#region Remove ... + public callRemove( + id: TKey, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callRemove( + id: TKey, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callRemove( + id: TKey, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callRemove( + id: TKey, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(id); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.Remove, { + key: XBaseEndPointParam.XId, + value: toXString(id), + }); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region RemoveMany ... + public callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public callRemoveMany( + body: XBaseRangeRequestDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(body); + XValidators.validateHasChilds(body.items); + + // + // Instantiiate Headers from Default Headers ... + let headers = this.defaultHeaders; + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XBaseEndPointAction, + XBaseEndPointParam + >(XBaseEndPointAction.RemoveMany); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, body, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/base/x-base.guard.ts b/projects/x-saherelm-api-sdk/src/lib/base/x-base.guard.ts new file mode 100644 index 0000000..b11f589 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/base/x-base.guard.ts @@ -0,0 +1,111 @@ +import { + Route, + CanLoad, + UrlTree, + UrlSegment, + CanActivate, + CanActivateChild, + RouterStateSnapshot, + ActivatedRouteSnapshot, +} from '@angular/router'; +import { Observable } from 'rxjs'; +import { + XAccountService, + XFrameworkIdentitySDKConfig, + X_FRAMEWORK_IDENTITY_SDK_CONFIG, +} from 'x-framework-identity-sdk'; +import { filter, map, tap } from 'rxjs/operators'; +import { Inject, Injectable } from '@angular/core'; +import { XManagerService } from 'x-framework-services'; +import { XAvailableRoles } from '../typings/x-role.typings'; +import { checkIsInRoleByInfo, toRoleInfo } from '../tools/x-role.tools'; +import { isNullOrUndefined, XExceptionIDs, XLoggable, XOneOrManyType } from 'x-framework-core'; + +@Injectable({ + providedIn: 'root', +}) +export abstract class XBaseGuard + extends XLoggable + implements CanActivate, CanActivateChild, CanLoad +{ + // + abstract roles: XOneOrManyType; + + // + constructor( + private authService: XAccountService, + private managerService: XManagerService, + @Inject(X_FRAMEWORK_IDENTITY_SDK_CONFIG) + public config: XFrameworkIdentitySDKConfig + ) { + super(config); + } + + // + //#region Actions ... + // + canActivate( + next: ActivatedRouteSnapshot, + state: RouterStateSnapshot + ): + | Observable + | Promise + | boolean + | UrlTree { + return this.handleGuard(); + } + + // + canActivateChild( + next: ActivatedRouteSnapshot, + state: RouterStateSnapshot + ): + | Observable + | Promise + | boolean + | UrlTree { + return this.handleGuard(); + } + + // + canLoad( + route: Route, + segments: UrlSegment[] + ): Observable | Promise | boolean { + return this.handleGuard(); + } + //#endregion + + // + //#region Private Action ... + private handleGuard(): Observable { + return this.authService.state$.pipe( + filter( + (state) => + !isNullOrUndefined(state) && !!state.isLoggedIn && !!state.profile + ), + map((state) => state.profile), + map((user) => toRoleInfo(user)), + map((roleInfo) => checkIsInRoleByInfo(this.roles, roleInfo)), + tap((isPassed) => { + // + if (!isPassed) { + this.handleGuardReject(); + } + }) + ); + } + + // + private handleGuardReject(): void { + // + this.managerService.notificationService.presentErrorNotification({ + exception: XExceptionIDs.NotAllowed, + dissmissable: true, + }); + + // + this.managerService.navigateByPage(this.config.Pages.Login); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/config/x-saherelm-api-sdk.config.ts b/projects/x-saherelm-api-sdk/src/lib/config/x-saherelm-api-sdk.config.ts new file mode 100644 index 0000000..6fc1272 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/config/x-saherelm-api-sdk.config.ts @@ -0,0 +1,19 @@ +import { XFrameworkCoreConfig } from 'x-framework-core'; +import { XFrameworkServicesConfig } from 'x-framework-services'; +import { XFrameworkIdentitySDKConfig } from 'x-framework-identity-sdk'; + +export type XSharedConfig = XFrameworkCoreConfig & + XFrameworkServicesConfig & + XFrameworkIdentitySDKConfig & { [key: string]: any }; + +// tslint:disable-next-line:no-empty-interface +export interface XSaherElmApiSDKConfig extends XSharedConfig { + // + // Push Service Configuration ... + pushMessageAction: string; + pushServiceRoute: string; + pushManagerReconnectDelay: number; + + // + corsBypasserProxy: string; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/configurations/x-configurations.service.ts b/projects/x-saherelm-api-sdk/src/lib/configurations/x-configurations.service.ts new file mode 100644 index 0000000..9e241e1 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/configurations/x-configurations.service.ts @@ -0,0 +1,30 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable, Inject } from '@angular/core'; +import { XApiEndPoint } from '../typings/x-endpoint.typings'; +import { X_SAHERELM_API_SDK_CONFIG } from '../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../config/x-saherelm-api-sdk.config'; +import { XApiConfiguration, XBaseApiService, X_API_CONFIG } from 'x-framework-identity-sdk'; + +@Injectable({ + providedIn: 'root', +}) +export class XConfigurationsService extends XBaseApiService { + // + //#region Constructor ... + constructor( + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + // + super( + XApiEndPoint.Configurations, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/files/models/x-file.dto.ts b/projects/x-saherelm-api-sdk/src/lib/files/models/x-file.dto.ts new file mode 100644 index 0000000..dc3077d --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/files/models/x-file.dto.ts @@ -0,0 +1,203 @@ +import { + XBaseDto, + hasChild, + XFileType, + typeGuard, + isSameObject, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; +import { + XReferenceDto, + parseXReferences, + references2String, +} from '../../models/x-reference.dto'; +import { XPersonDto } from '../../models/x-person.dto'; + +/** + * a Model for Describing a File ... + */ +export interface XFileEntity extends XBaseDto { + id: string; + type: XFileType; + name: string; + thumb?: string; + path: string; + thumbPath?: string; + uploadedOn: Date; + fileName?: string; + ownerId: string; + references: string; +} + +/** + * a Model for Describing a File ... + */ +export interface XFileDto extends XBaseDto { + id: string; + type: XFileType; + name: string; + thumb?: string; + path: string; + thumbPath?: string; + uploadedOn: Date; + fileName?: string; + ownerId: string; + owner?: XPersonDto; + references: Array>; +} + +/** + * Default model ... + */ +export const defaultFileDto: XFileDto = { + id: '', + name: '', + path: '', + ownerId: '', + references: [], + type: undefined, + thumb: undefined, + owner: undefined, + fileName: undefined, + thumbPath: undefined, + uploadedOn: undefined, +}; + +/** + * Preparing Dto Field ... + * + * @param model + */ +export function prepareFileDtoFields(model?: XFileDto) { + // + if (isNullOrUndefined(model)) { + // + model = { + ...defaultFileDto, + }; + } + + // + model = { + id: !isNullOrEmptyString(model.id) ? model.id : defaultFileDto.id, + name: !isNullOrEmptyString(model.name) ? model.name : defaultFileDto.name, + path: !isNullOrEmptyString(model.path) ? model.path : defaultFileDto.path, + ownerId: !isNullOrEmptyString(model.ownerId) + ? model.ownerId + : defaultFileDto.ownerId, + references: + !isNullOrUndefined(model.references) && !hasChild(model.references) + ? [...model.references] + : defaultFileDto.references, + type: !isNullOrUndefined(model.type) ? model.type : defaultFileDto.type, + thumb: !isNullOrEmptyString(model.thumb) + ? model.thumb + : defaultFileDto.thumb, + owner: !isNullOrUndefined(model.owner) + ? { ...model.owner } + : defaultFileDto.owner, + fileName: !isNullOrEmptyString(model.fileName) + ? model.fileName + : defaultFileDto.fileName, + thumbPath: !isNullOrEmptyString(model.thumbPath) + ? model.thumbPath + : defaultFileDto.thumbPath, + uploadedOn: !isNullOrUndefined(model.uploadedOn) + ? model.uploadedOn + : defaultFileDto.uploadedOn, + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + */ +export function isDefaultFileDto(model?: XFileDto) { + return isSameObject(prepareFileDtoFields(model), defaultFileDto); +} + +/** + * Model Type Guard ... + */ +export const isXFileDto = typeGuard([ + 'id', + 'name', + 'ownerId', + 'type', + 'uploadedOn', + 'path', +]); + +/** + * Converts a FileDto to Entity ... + * + * @param value + * @returns + */ +export function fileDtoToEntity(value: XFileDto) { + // + let result: XFileEntity = undefined; + + // + if (!isNullOrUndefined(value) && isXFileDto(value)) { + // + const references = references2String(value.references); + result = { + id: value.id, + type: value.type, + name: value.name, + thumb: value.thumb, + path: value.path, + thumbPath: value.thumbPath, + uploadedOn: value.uploadedOn, + fileName: value.fileName, + ownerId: value.ownerId, + references, + }; + } + + // + return result; +} + +/** + * Converts a FileEntity to Dto ... + * + * @param value + * @param owner + * @returns + */ +export function fileEntityToDto( + value: XFileEntity, + owner: XPersonDto = undefined +) { + // + let result: XFileDto = undefined; + + // + if (!isNullOrUndefined(value) && isXFileDto(value)) { + // + const references = parseXReferences(value.references); + result = { + id: value.id, + type: value.type, + name: value.name, + thumb: value.thumb, + path: value.path, + thumbPath: value.thumbPath, + uploadedOn: value.uploadedOn, + fileName: value.fileName, + ownerId: value.ownerId, + owner, + references, + }; + } + + // + return result; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.entity.push.service.ts b/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.entity.push.service.ts new file mode 100644 index 0000000..078afda --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.entity.push.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from "@angular/core"; +import { XFileEntity } from "../models/x-file.dto"; +import { XBaseEntityPushService } from "x-framework-push-service"; +import { HttpTransportType, ITransport } from "@microsoft/signalr"; + +@Injectable({ + providedIn: 'root' +}) +export class XFileEntityPushService extends XBaseEntityPushService { + // + //#region Abstracts ... + hubName(): string { + return 'fileEntityHub'; + } + + requiredAccessToken(): boolean { + return true; + } + + transportType(): HttpTransportType | ITransport { + return HttpTransportType.LongPolling; + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.entity.service.ts b/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.entity.service.ts new file mode 100644 index 0000000..c191b69 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.entity.service.ts @@ -0,0 +1,39 @@ +import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { Inject, Injectable } from '@angular/core'; +import { XFileEntity } from '../models/x-file.dto'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XBaseEntityService } from '../../base/x-base-entity.service'; +import { X_API_CONFIG, XApiConfiguration } from 'x-framework-identity-sdk'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; + +/** + * Provides all Entity Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XFileEntityService extends XBaseEntityService< + XFileEntity, + string +> { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.FilesEntity, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.provider.service.ts b/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.provider.service.ts new file mode 100644 index 0000000..8d62ea1 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/files/services/x-file.provider.service.ts @@ -0,0 +1,1008 @@ +import { + toArray, + hasChild, + XValidators, + XOneOrManyType, + isNullOrEmptyString, +} from 'x-framework-core'; +import { + HttpEvent, + HttpParams, + HttpClient, + HttpHeaders, + HttpResponse, +} from '@angular/common/http'; +import { + XQueryDto, + X_API_CONFIG, + XBaseApiService, + XQueryResultDto, + XApiConfiguration, +} from 'x-framework-identity-sdk'; +import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; +import { XFileDto } from '../models/x-file.dto'; +import { Inject, Injectable } from '@angular/core'; +import { fillRouteParams } from '../../tools/x-route.tools'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XFileParam, XFileServiceRoute } from '../x-file.typings'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; +import { applyConnectionIdToHeader } from '../../typings/x-push-provider.typings'; + +/** + * Provides all Provider Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XFileProviderService extends XBaseApiService { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super(XApiEndPoint.FilesService, true, true, httpClient, config, apiConfig); + } + //#endregion + + // + //#region Tools ... + // + //#region StreamById ... + /** + * Stream Specified File ... + * + * @param id + * @param observe + * @param reportProgress + */ + public streamById( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public streamById( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public streamById( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public streamById( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.StreamById), + // + // Params ... + [ + { + key: XFileParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + responseType: 'arraybuffer', + reportProgress, + }); + } + //#endregion + + // + //#region StreamByName ... + /** + * Stream Specified File ... + * + * @param name + * @param observe + * @param reportProgress + */ + public streamByName( + name: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public streamByName( + name: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public streamByName( + name: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public streamByName( + name: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(name); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.StreamByName), + // + // Params ... + [ + { + key: XFileParam.Name, + value: name, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + responseType: 'arraybuffer', + reportProgress, + }); + } + //#endregion + + // + //#region DownloadById ... + /** + * Download Specified File ... + * + * @param id + * @param observe + * @param reportProgress + */ + public downloadById( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public downloadById( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public downloadById( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public downloadById( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.DownloadById), + // + // Params ... + [ + { + key: XFileParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + responseType: 'blob', + reportProgress, + }); + } + //#endregion + + // + //#region DownloadByName ... + /** + * Download Specified File ... + * + * @param name + * @param observe + * @param reportProgress + */ + public downloadByName( + name: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public downloadByName( + name: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public downloadByName( + name: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public downloadByName( + name: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(name); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.DownloadByName), + // + // Params ... + [ + { + key: XFileParam.Name, + value: name, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + responseType: 'blob', + reportProgress, + }); + } + //#endregion + + // + //#region Upload ... + /** + * Upload ... + * + * @param files + * @param connectionId + * @param observe + * @param reportProgress + */ + public upload( + files: XOneOrManyType, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public upload( + files: XOneOrManyType, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public upload( + files: XOneOrManyType, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public upload( + files: XOneOrManyType, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(files); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Preparing Form Data ... + let formData = new FormData(); + const filesArr = toArray(files); + if (hasChild(filesArr)) { + // + // Convert Files Array to Form Data ... + filesArr.forEach((f) => { + formData.append(XFileParam.Files, f, f.name); + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XFileServiceRoute.Upload); + + // + // Prepare Result ... + return this.httpClient.post>(endPointPath, formData, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Remove ... + /** + * Remove Files ... + * + * @param id + * @param ids + * @param connectionId + * @param observe + * @param reportProgress + */ + public remove( + ids?: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public remove( + ids?: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public remove( + ids?: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public remove( + ids?: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(ids); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Adding ids to Parmas ... + if (!isNullOrEmptyString(ids)) { + // + params = this.addCustomParam(params, { + key: XFileParam.Ids, + value: ids, + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XFileServiceRoute.Remove); + + // + // Prepare Result ... + return this.httpClient.delete>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Model ... + // + //#region Get ... + /** + * Get Specified Model ... + */ + public get( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public get( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public get( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public get( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.Get), + // + // Params ... + [ + { + key: XFileParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region All ... + /** + * Retrieve all Exists Models ... + * + * @param observe + * @param reportProgress + */ + public all( + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public all( + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public all( + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public all( + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XFileServiceRoute.All); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Query ... + /** + * Query Model ... + * + * @param query + * @param observe + * @param reportProgress + */ + public query( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public query( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public query( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public query( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XFileServiceRoute.Query); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region QueryOwned ... + /** + * Query Owned Models ... + * + * @param query + * @param observe + * @param reportProgress + */ + public queryOwned( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public queryOwned( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public queryOwned( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public queryOwned( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XFileServiceRoute.QueryOwned); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Tags ... + // + //#region AttachTags ... + /** + * Attach Specified Tags of Specified Model ... + * + * @param id + * @param tags + * @param connectionId + * @param observe + * @param reportProgress + */ + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tags to Params ... + if (!isNullOrEmptyString(tags)) { + // + params = this.addCustomParam(params, { + key: XFileParam.Tags, + value: tags, + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.AttachTags), + // + // Params ... + [ + { + key: XFileParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region DetachTags ... + /** + * Detach Specified Tags of Specified Model ... + * + * @param id + * @param tags + * @param connectionId + * @param observe + * @param reportProgress + */ + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tags to Params ... + if (!isNullOrEmptyString(tags)) { + // + params = this.addCustomParam(params, { + key: XFileParam.Tags, + value: tags, + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.DetachTags), + // + // Params ... + [ + { + key: XFileParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetTags ... + /** + * Retrieve Tags of Specified Model ... + * + * @param id + * @param observe + * @param reportProgress + */ + public getTags( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public getTags( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public getTags( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public getTags( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XFileServiceRoute.GetTags), + // + // Params ... + [ + { + key: XFileParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/files/x-file.services.ts b/projects/x-saherelm-api-sdk/src/lib/files/x-file.services.ts new file mode 100644 index 0000000..9fca7ae --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/files/x-file.services.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { XFileEntityService } from './services/x-file.entity.service'; +import { XFileProviderService } from './services/x-file.provider.service'; +import { XFileEntityPushService } from './services/x-file.entity.push.service'; + +/** + * Export All Provided File related Services ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XFileServices { + // + //#region Constructor ... + public constructor( + public fileEntityService: XFileEntityService, + public fileProviderService: XFileProviderService, + public fileEntityPushService: XFileEntityPushService + ) {} + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/files/x-file.typings.ts b/projects/x-saherelm-api-sdk/src/lib/files/x-file.typings.ts new file mode 100644 index 0000000..0c74970 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/files/x-file.typings.ts @@ -0,0 +1,29 @@ +/** + * All Available EndPoint Routes ... + */ +export enum XFileServiceRoute { + All = 'All', + Upload = '', + Remove = '', + Get = '{id}', + Query = 'Query', + GetTags = '{id}/Tags', + QueryOwned = 'Query/Owned', + StreamById = '{id}/Stream/ById', + AttachTags = '{id}/Tags/AttachMany', + DetachTags = '{id}/Tags/DetachMany', + DownloadById = '{id}/Download/ById', + StreamByName = '{name}/Stream/ByName', + DownloadByName = '{id}/Download/ByName', +} + +/** + * All Params Which Used in Related Services ... + */ +export enum XFileParam { + Id = 'id', + Ids = 'ids', + Tags = 'tags', + Name = 'name', + Files = 'files', +} diff --git a/projects/x-saherelm-api-sdk/src/lib/guards/admin-or-agent.guard.ts b/projects/x-saherelm-api-sdk/src/lib/guards/admin-or-agent.guard.ts new file mode 100644 index 0000000..9fffbb0 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/guards/admin-or-agent.guard.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { XBaseGuard } from '../base/x-base.guard'; +import { XAvailableRoles } from '../typings/x-role.typings'; + +@Injectable({ + providedIn: 'root', +}) +export class AdminOrAgentGuard extends XBaseGuard { + roles = [ + XAvailableRoles.Admin, + XAvailableRoles.Agent + ]; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/guards/admin.guard.ts b/projects/x-saherelm-api-sdk/src/lib/guards/admin.guard.ts new file mode 100644 index 0000000..cebf881 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/guards/admin.guard.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@angular/core'; +import { XBaseGuard } from '../base/x-base.guard'; +import { XAvailableRoles } from '../typings/x-role.typings'; + +@Injectable({ + providedIn: 'root', +}) +export class AdminGuard extends XBaseGuard { + roles = XAvailableRoles.Admin; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/guards/agent.guard.ts b/projects/x-saherelm-api-sdk/src/lib/guards/agent.guard.ts new file mode 100644 index 0000000..de8ac65 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/guards/agent.guard.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@angular/core'; +import { XBaseGuard } from '../base/x-base.guard'; +import { XAvailableRoles } from '../typings/x-role.typings'; + +@Injectable({ + providedIn: 'root', +}) +export class AgentGuard extends XBaseGuard { + roles = XAvailableRoles.Agent; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/guards/user.guard.ts b/projects/x-saherelm-api-sdk/src/lib/guards/user.guard.ts new file mode 100644 index 0000000..d6d350d --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/guards/user.guard.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@angular/core'; +import { XBaseGuard } from '../base/x-base.guard'; +import { XAvailableRoles } from '../typings/x-role.typings'; + +@Injectable({ + providedIn: 'root', +}) +export class UserGuard extends XBaseGuard { + roles = XAvailableRoles.User; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/models/x-person.dto.ts b/projects/x-saherelm-api-sdk/src/lib/models/x-person.dto.ts new file mode 100644 index 0000000..1b53aa4 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/models/x-person.dto.ts @@ -0,0 +1,80 @@ +import { + XBaseDto, + typeGuard, + isSameObject, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; + +/** + * Simply Represent a User ... + */ +export interface XPersonDto extends XBaseDto { + username: string; + firstname: string; + lastname: string; + avatar: string; +} + +/** + * Default Model ... + */ +export const defaultPersonDto: XPersonDto = { + username: '', + firstname: '', + lastname: '', + avatar: '', +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function preparePersonDtoFields(model?: XPersonDto) { + // + if (isNullOrUndefined(model)) { + model = { + ...defaultPersonDto, + }; + } + + // + model = { + avatar: isNullOrEmptyString(model.avatar) + ? defaultPersonDto.avatar + : model.avatar, + username: isNullOrEmptyString(model.username) + ? defaultPersonDto.username + : model.username, + lastname: isNullOrEmptyString(model.lastname) + ? defaultPersonDto.lastname + : model.lastname, + firstname: isNullOrEmptyString(model.firstname) + ? defaultPersonDto.firstname + : model.firstname, + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultPersonDto(model?: XPersonDto) { + return isSameObject(preparePersonDtoFields(model), defaultPersonDto); +} + +/** + * Model Type Guard ... + */ +export const isXPersonDto = typeGuard([ + 'username', + 'firstname', + 'lastname', +]); diff --git a/projects/x-saherelm-api-sdk/src/lib/models/x-reference.dto.ts b/projects/x-saherelm-api-sdk/src/lib/models/x-reference.dto.ts new file mode 100644 index 0000000..83459e4 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/models/x-reference.dto.ts @@ -0,0 +1,213 @@ +import { + nameof, + toNumber, + XBaseDto, + hasChild, + toXString, + typeGuard, + isSameObject, + toListString, + parseListString, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; + +export interface XReferenceDto extends XBaseDto { + index: number; + providedFor: string; + referencedTo: T; +} + +/** + * Model Type Guard ... + */ +export const isXReferenceDto = typeGuard>([ + 'index', + 'providedFor', + 'referencedTo', +]); + +export const defaultReferenceDto: XReferenceDto = { + index: 0, + providedFor: '', + referencedTo: undefined, +}; + +export function prepareReferenceDtoFields(model?: XReferenceDto) { + // + if (isNullOrUndefined(model)) { + // + model = { + ...defaultReferenceDto, + }; + } + + // + model = { + index: !isNullOrUndefined(model.index) + ? model.index + : defaultReferenceDto.index, + referencedTo: !isNullOrUndefined(model.referencedTo) + ? model.referencedTo + : defaultReferenceDto.referencedTo, + providedFor: !isNullOrEmptyString(model.providedFor) + ? model.providedFor + : defaultReferenceDto.providedFor, + }; + + // + return model; +} + +export function isDefaultReferenceDto(model?: XReferenceDto) { + return isSameObject(prepareReferenceDtoFields(model), defaultReferenceDto); +} + +/** + * Converts any object to XReferenceDto ... + * + * @param value + * @returns + */ +export function parseXReferenceDto(value: any) { + // + let result: XReferenceDto = undefined; + + // + let isPassed = false; + isPassed = + !isNullOrUndefined(value) && + Object.keys(value).includes(nameof>('index')) && + Object.keys(value).includes(nameof>('referencedTo')) && + Object.keys(value).includes(nameof>('providedFor')); + if (isPassed) { + // + result = { + index: toNumber(value.index), + providedFor: toXString(value.providedFor), + referencedTo: value.referencedTo as unknown as T, + }; + } + + // + return result; +} + +/** + * Parse an String to XReferenceDto ... + * + * @param value + * @returns + */ +export function parseXReference(value: string) { + // + var result: XReferenceDto = undefined; + + // + if (!isNullOrEmptyString(value)) { + // + let parts = parseListString(value, '_'); + let isValid = + !isNullOrUndefined(parts) && hasChild(parts) && parts.length >= 3; + + // + if (isValid) { + // + result = { + index: toNumber(parts[2]), + referencedTo: parts[1] as unknown as T, + providedFor: toXString(parts[0]), + }; + } + } + + // + return result; +} + +/** + * Parse References List From String ... + * + * @param value + * @returns + */ +export function parseXReferences(value: string) { + // + let result: Array> = []; + + // + if (!isNullOrEmptyString(value)) { + // + let parts = parseListString(value); + let isValid = !isNullOrUndefined(parts) && hasChild(parts); + if (isValid) { + // + parts.forEach((part) => { + // + var reference = parseXReference(part); + isValid = !isNullOrUndefined(reference); + if (isValid) { + result.push(reference); + } + }); + } + } + + // + return result; +} + +/** + * Converts an XReferenceDto to String Reperesentation ... + * + * @param value + * @param separator + * @returns + */ +export function reference2String( + value: XReferenceDto, + separator: string = '_' +) { + // + let result: string = undefined; + + // + if (!isNullOrUndefined(value)) { + result = `${value.providedFor}${separator}${value.referencedTo}${separator}${value.index}`; + } + + // + return result; +} + +/** + * Converts references Array to String Representation ... + * + * @param value + * @param separator + * @returns + */ +export function references2String( + value: Array>, + separator: string = ',' +) { + // + let result: string = undefined; + + // + let arr: Array = []; + if (!isNullOrUndefined(value) && hasChild(value)) { + // + value.forEach((v) => { + // + let refStr = reference2String(v); + arr.push(refStr); + }); + } + + // + result = toListString(arr, separator); + + // + return result; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/services/x-push-token-fetcher.service.ts b/projects/x-saherelm-api-sdk/src/lib/services/x-push-token-fetcher.service.ts new file mode 100644 index 0000000..41b7147 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/services/x-push-token-fetcher.service.ts @@ -0,0 +1,55 @@ +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { Inject, Injectable } from '@angular/core'; +import { XAccountService } from 'x-framework-identity-sdk'; +import { isNullOrUndefined, XBaseService } from 'x-framework-core'; +import { IXPushServiceTokenFetcher } from 'x-framework-push-service'; +import { X_SAHERELM_API_SDK_CONFIG } from '../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../config/x-saherelm-api-sdk.config'; + +@Injectable({ + providedIn: 'root', +}) +export class XPushTokenFetcherService + extends XBaseService + implements IXPushServiceTokenFetcher +{ + // + //#region Props ... + token: string; + token$: Observable = this.accountsService.state$.pipe( + map((state) => (isNullOrUndefined(state) ? null : state.accessToken)) + ); + //#endregion + + // + //#region Constructor ... + constructor( + // + @Inject(X_SAHERELM_API_SDK_CONFIG) + public config: XSaherElmApiSDKConfig, + // + public accountsService: XAccountService + ) { + super(config); + + // + accountsService.state$.subscribe((state) => { + // + if (isNullOrUndefined(state)) { + this.token = null; + } else { + this.token = state.accessToken; + } + }); + } + //#endregion + + /** + * retrieve current user's access token ... + * @returns token + */ + public getToken(): string { + return this.token; + } +} diff --git a/projects/x-saherelm-api-sdk/src/lib/strings/models/x-string.dto.ts b/projects/x-saherelm-api-sdk/src/lib/strings/models/x-string.dto.ts new file mode 100644 index 0000000..25908ee --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/strings/models/x-string.dto.ts @@ -0,0 +1,192 @@ +import { + XBaseDto, + hasChild, + typeGuard, + isSameObject, + XBaseNumberIDDto, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; + +/** + * Represent a Locale Resource ... + */ +export interface XStringDto extends XBaseNumberIDDto { + language: string; + resourceTitle: string; + translatedValue: string; +} + +/** + * Default Model ... + */ +export const defaultStringDto: XStringDto = { + id: undefined, + language: '', + resourceTitle: '', + translatedValue: '', +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function prepareStringDtoFields(model?: XStringDto) { + // + if (isNullOrUndefined(model)) { + model = { + ...defaultStringDto, + }; + } + + // + model = { + id: isNullOrUndefined(model.id) ? defaultStringDto.id : model.id, + language: isNullOrEmptyString(model.language) + ? defaultStringDto.language + : model.language, + resourceTitle: isNullOrEmptyString(model.resourceTitle) + ? defaultStringDto.resourceTitle + : model.resourceTitle, + translatedValue: isNullOrEmptyString(model.translatedValue) + ? defaultStringDto.translatedValue + : model.translatedValue, + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultStringDto(model?: XStringDto) { + return isSameObject(prepareStringDtoFields(model), defaultStringDto); +} + +/** + * Simply Represent a Locale ... + */ +export interface XLocaleResourceDto extends XBaseDto { + language: string; + value: string; +} + +/** + * Default Model ... + */ +export const defaultLocaleResourceDto: XLocaleResourceDto = { + value: '', + language: '', +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function prepareLocaleResourceDtoFields(model?: XLocaleResourceDto) { + // + if (isNullOrUndefined(model)) { + model = { + ...defaultLocaleResourceDto, + }; + } + + // + model = { + value: isNullOrEmptyString(model.value) + ? defaultLocaleResourceDto.value + : model.value, + language: isNullOrEmptyString(model.language) + ? defaultLocaleResourceDto.language + : model.language, + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultLocaleResourceDto(model?: XLocaleResourceDto) { + return isSameObject( + prepareLocaleResourceDtoFields(model), + defaultLocaleResourceDto + ); +} + +/** + * Represent a Locale by it's Resources ... + */ +export interface XResourceDto extends XBaseDto { + resource: string; + locales: Array; +} + +/** + * Default Model ... + */ +export const defaultResourceDto: XResourceDto = { + resource: '', + locales: [], +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function prepareResourceDtoFields(model?: XResourceDto) { + // + if (isNullOrUndefined(model)) { + model = { + ...defaultResourceDto, + }; + } + + // + model = { + resource: isNullOrEmptyString(model.resource) + ? defaultResourceDto.resource + : model.resource, + locales: + isNullOrUndefined(model.locales) || !hasChild(model.locales) + ? defaultResourceDto.locales + : model.locales.map((l) => prepareLocaleResourceDtoFields(l)), + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultResourceDto(model?: XResourceDto) { + return isSameObject(prepareResourceDtoFields(model), defaultResourceDto); +} + +/** + * Model Type Guard ... + */ +export const isXStringDto = typeGuard([ + 'id', + 'language', + 'resourceTitle', + 'translatedValue', +]); diff --git a/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.entity.push.service.ts b/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.entity.push.service.ts new file mode 100644 index 0000000..8af66da --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.entity.push.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { XStringDto } from '../models/x-string.dto'; +import { XBaseEntityPushService } from 'x-framework-push-service'; +import { HttpTransportType, ITransport } from '@microsoft/signalr'; + +@Injectable({ + providedIn: 'root', +}) +export class XStringEntityPushService extends XBaseEntityPushService { + // + //#region Abstracts ... + hubName(): string { + return 'stringEntityHub'; + } + + requiredAccessToken(): boolean { + return true; + } + + transportType(): HttpTransportType | ITransport { + return HttpTransportType.LongPolling; + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.entity.service.ts b/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.entity.service.ts new file mode 100644 index 0000000..2d70b3f --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.entity.service.ts @@ -0,0 +1,39 @@ +import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { Inject, Injectable } from '@angular/core'; +import { XStringDto } from '../models/x-string.dto'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XBaseEntityService } from '../../base/x-base-entity.service'; +import { X_API_CONFIG, XApiConfiguration } from 'x-framework-identity-sdk'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; + +/** + * Provides all Entity Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XStringEntityService extends XBaseEntityService< + XStringDto, + number +> { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.StringsEntity, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.provider.service.ts b/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.provider.service.ts new file mode 100644 index 0000000..c11230e --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/strings/services/x-string.provider.service.ts @@ -0,0 +1,1842 @@ +import { + HttpEvent, + HttpClient, + HttpParams, + HttpHeaders, + HttpResponse, +} from '@angular/common/http'; +import { + XQueryDto, + XStringDto, + X_API_CONFIG, + XBaseApiService, + XQueryResultDto, + XApiConfiguration, +} from 'x-framework-identity-sdk'; +import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; +import { + XApiEndPoint, + XBaseEndPointParam, +} from '../../typings/x-endpoint.typings'; +import { XValidators } from 'x-framework-core'; +import { Inject, Injectable } from '@angular/core'; +import { XStringParam, XStringsServiceRoute } from '../x-string.typings'; +import { XLocaleResourceDto, XResourceDto } from '../models/x-string.dto'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; +import { applyConnectionIdToHeader } from '../../typings/x-push-provider.typings'; + +/** + * Provides all Provider Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XStringProviderService extends XBaseApiService { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.StringsService, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion + + // + //#region Actions ... + // + //#region Retrievers ... + // + //#region Get ... + /** + * Retrieve Specified Resource ... + * + * @param resource + * @param language + * @param observe + * @param reportProgress + */ + public get( + resource: string, + language: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public get( + resource: string, + language: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public get( + resource: string, + language: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public get( + resource: string, + language: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.Get); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Languages ... + /** + * Retrieve all Available Languages List ... + * + * @param observe + * @param reportProgress + */ + public languages( + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public languages( + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public languages( + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public languages( + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.Languages); + + // + // Preparing HttpParams ... + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Resources ... + /** + * Retrieve Specified Resource Items as XResourceDto Presentation ... + * + * @param resource + * @param observe + * @param reportProgress + */ + public resources( + resource: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public resources( + resource: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public resources( + resource: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public resources( + resource: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.Resources); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AsResource ... + /** + * Retrieve Specified Resource Items as XResourceDto Presentation ... + * + * @param resource + * @param observe + * @param reportProgress + */ + public asResource( + resource: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public asResource( + resource: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public asResource( + resource: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public asResource( + resource: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AsResource); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region ResourceValue ... + /** + * Retrieve Specified Translation of Specified Resource ... + * + * @param resource + * @param language + * @param observe + * @param reportProgress + */ + public resourceValue( + resource: string, + language: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public resourceValue( + resource: string, + language: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public resourceValue( + resource: string, + language: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public resourceValue( + resource: string, + language: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.ResourceValue); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region IsResourceExists ... + /** + * Check Specified Resource Exists or not ... + * + * @param resource + * @param language + * @param observe + * @param reportProgress + */ + public isResourceExists( + resource: string, + language: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public isResourceExists( + resource: string, + language: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public isResourceExists( + resource: string, + language: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public isResourceExists( + resource: string, + language: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.IsResourceExists); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Query ... + // + //#region QueryResourceIds ... + /** + * Query Resource IDs ... + * + * @param query + * @param observe + * @param reportProgress + */ + public queryResourceIds( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public queryResourceIds( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public queryResourceIds( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public queryResourceIds( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Query as Params ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.QueryResourceIds); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region QueryLocaleResources ... + /** + * Query Locale Resources ... + * + * @param query + * @param language + * @param observe + * @param reportProgress + */ + public queryLocaleResources( + query: XQueryDto, + language: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public queryLocaleResources( + query: XQueryDto, + language: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public queryLocaleResources( + query: XQueryDto, + language: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public queryLocaleResources( + query: XQueryDto, + language: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Query as Params ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.QueryLocaleResources); + + // + // Prepare Result ... + return this.httpClient.get>( + endPointPath, + { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + } + ); + } + //#endregion + + // + //#region QueryLanguageResources ... + /** + * Query Specified Language Resources ... + * + * @param query + * @param language + * @param observe + * @param reportProgress + */ + public queryLanguageResources( + query: XQueryDto, + language: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public queryLanguageResources( + query: XQueryDto, + language: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public queryLanguageResources( + query: XQueryDto, + language: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public queryLanguageResources( + query: XQueryDto, + language: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Query as Params ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.QueryLocaleResources); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Add ... + // + //#region Add ... + /** + * Add Specified Resource ... + * + * @param resource + * @param value + * @param language + * @param connectionId + * @param observe + * @param reportProgress + */ + public add( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public add( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public add( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public add( + resource: string, + value: string, + language: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(value); + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.Add); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Value, + value: value, + }); + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AddModel ... + /** + * Add Specified Resource ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public addModel( + model: XStringDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public addModel( + model: XStringDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public addModel( + model: XStringDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public addModel( + model: XStringDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.resourceTitle); + XValidators.validateNotEmpty(model.translatedValue); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AddModel); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AddLocale ... + /** + * Add Specified Locale Resource ... + * + * @param model + * @param resource + * @param connectionId + * @param observe + * @param reportProgress + */ + public addLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public addLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public addLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public addLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(model.value); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AddLocale); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AddResource ... + /** + * Add Or Update all XResourceDto(s) Locales ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public addResource( + model: XResourceDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public addResource( + model: XResourceDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public addResource( + model: XResourceDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public addResource( + model: XResourceDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.resource); + XValidators.validateHasChilds(model.locales); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AddResource); + + // + // Preparing HttpParams ... + + // + // Prepare Result ... + return this.httpClient.post>(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AddOrUpdate ... + /** + * Add Or Update Resource ... + * + * @param resource + * @param value + * @param language + * @param connectionId + * @param observe + * @param reportProgress + */ + public addOrUpdate( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public addOrUpdate( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public addOrUpdate( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public addOrUpdate( + resource: string, + value: string, + language: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(value); + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AddOrUpdate); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Value, + value: value, + }); + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AddOrUpdateModel ... + /** + * Add Or Update Resource ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public addOrUpdateModel( + model: XStringDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public addOrUpdateModel( + model: XStringDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public addOrUpdateModel( + model: XStringDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public addOrUpdateModel( + model: XStringDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.resourceTitle); + XValidators.validateNotEmpty(model.translatedValue); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AddOrUpdateModel); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region AddOrUpdateLocale ... + /** + * Add Or Update Specified Locale Resource ... + * + * @param model + * @param resource + * @param connectionId + * @param observe + * @param reportProgress + */ + public addOrUpdateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public addOrUpdateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public addOrUpdateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public addOrUpdateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(model.value); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.AddOrUpdateLocale); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Update ... + // + //#region Update ... + /** + * Update Specified Resource ... + * + * @param resource + * @param value + * @param language + * @param connectionId + * @param observe + * @param reportProgress + */ + public update( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public update( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public update( + resource: string, + value: string, + language: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public update( + resource: string, + value: string, + language: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(value); + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.Update); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Value, + value: value, + }); + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region UpdateModel ... + /** + * Update Specified Resource ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public updateModel( + model: XStringDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public updateModel( + model: XStringDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public updateModel( + model: XStringDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public updateModel( + model: XStringDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.resourceTitle); + XValidators.validateNotEmpty(model.translatedValue); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.UpdateModel); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region UpdateLocale ... + /** + * Update Specified Locale Resource ... + * + * @param model + * @param resource + * @param connectionId + * @param observe + * @param reportProgress + */ + public updateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public updateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public updateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public updateLocale( + model: XLocaleResourceDto, + resource: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(model.value); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.UpdateLocale); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Remove ... + // + //#region Remove ... + /** + * Remove Specified Resource ... + * + * @param resource + * @param language + * @param connectionId + * @param observe + * @param reportProgress + */ + public remove( + resource: string, + language: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public remove( + resource: string, + language: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public remove( + resource: string, + language: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public remove( + resource: string, + language: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Instantiiate Headers from Default Headers ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + params = this.addCustomParam(params, { + key: XStringParam.Language, + value: language, + }); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.Remove); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region RemoveLocales ... + public removeLocales( + resource: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public removeLocales( + resource: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public removeLocales( + resource: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public removeLocales( + resource: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(resource); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Instantiiate Headers from Default Headers ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Preparing HttpParams ... + params = this.addCustomParam(params, { + key: XStringParam.Resource, + value: resource, + }); + + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.RemoveLocales); + + // + // Prepare Result ... + return this.httpClient.delete>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region RemoveResource ... + /** + * Remove all Resource of Specified XResourceDto ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public removeResource( + model: XResourceDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public removeResource( + model: XResourceDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public removeResource( + model: XResourceDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public removeResource( + model: XResourceDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.resource); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Instantiiate Headers from Default Headers ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.RemoveResource); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + + // + //#region RemoveLanguage ... + /** + * Remove all Specified Language's Resources ... + * + * @param language + * @param connectionId + * @param observe + * @param reportProgress + */ + public removeLanguage( + language: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public removeLanguage( + language: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public removeLanguage( + language: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public removeLanguage( + language: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Instantiiate Headers from Default Headers ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute< + XStringsServiceRoute, + XBaseEndPointParam + >(XStringsServiceRoute.RemoveLanguage); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + reportProgress, + }); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/strings/x-string.services.ts b/projects/x-saherelm-api-sdk/src/lib/strings/x-string.services.ts new file mode 100644 index 0000000..6f0b6f4 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/strings/x-string.services.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { XStringEntityService } from './services/x-string.entity.service'; +import { XStringProviderService } from './services/x-string.provider.service'; +import { XStringEntityPushService } from './services/x-string.entity.push.service'; + +/** + * Export All Provided String related Services ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XStringServices { + // + //#region Constructor ... + public constructor( + public stringEntityService: XStringEntityService, + public stringProviderService: XStringProviderService, + public stringEntityPushService: XStringEntityPushService + ) {} + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/strings/x-string.typings.ts b/projects/x-saherelm-api-sdk/src/lib/strings/x-string.typings.ts new file mode 100644 index 0000000..886c4ba --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/strings/x-string.typings.ts @@ -0,0 +1,51 @@ +/** + * All Available EndPoint Routes ... + */ +export enum XStringsServiceRoute { + // + // Retrievers ... + Get = '', + Resources = 'Resources', + Languages = 'Languages', + AsResource = 'AsResource', + ResourceValue = 'ResourceValue', + IsResourceExists = 'IsResourceExists', + + // + // Query ... + QueryResourceIds = 'QueryResourceIds', + QueryLocaleResources = 'QueryLocaleResources', + QueryLanguageResourcs = 'QueryLanguageResourcs', + + // + // Add ... + Add = 'Add', + AddModel = 'AddModel', + AddLocale = 'AddLocale', + AddResource = 'AddResource', + AddOrUpdate = 'AddOrUpdate', + AddOrUpdateModel = 'AddOrUpdateModel', + AddOrUpdateLocale = 'AddOrUpdateLocale', + + // + // Update ... + Update = 'Update', + UpdateModel = 'UpdateModel', + UpdateLocale = 'UpdateLocale', + + // + // Remove ... + Remove = 'Remove', + RemoveLocales = 'RemoveLocales', + RemoveResource = 'RemoveResource', + RemoveLanguage = 'RemoveLanguage', +} + +/** + * All Params Which Used in Related Services ... + */ +export enum XStringParam { + Value = 'value', + Resource = 'resource', + Language = 'language', +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tags/models/x-tag.dto.ts b/projects/x-saherelm-api-sdk/src/lib/tags/models/x-tag.dto.ts new file mode 100644 index 0000000..83a6edd --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tags/models/x-tag.dto.ts @@ -0,0 +1,138 @@ +import { + hasChild, + XBaseDto, + typeGuard, + isSameObject, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; +import { + XReferenceDto, + parseXReferences, + references2String, +} from '../../models/x-reference.dto'; + +/** + * Represent Specified Tag ... + */ +export interface XTagEntity extends XBaseDto { + id: number; + tag: string; + references: string; +} + +/** + * Represent Specified Tag ... + */ +export interface XTagDto extends XBaseDto { + id: number; + tag: string; + references: Array>; +} + +/** + * Default Model ... + */ +export const defaultTagDto: XTagDto = { + id: 0, + tag: undefined, + references: [], +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function prepareTagDtoFields(model?: XTagDto) { + // + if (isNullOrUndefined(model)) { + // + model = { + ...defaultTagDto, + }; + } + + // + model = { + // + id: + !isNullOrUndefined(model.id) && model.id > 0 + ? model.id + : defaultTagDto.id, + tag: !isNullOrEmptyString(model.tag) ? model.tag : defaultTagDto.tag, + references: + !isNullOrUndefined(model.references) && hasChild(model.references) + ? [...model.references] + : defaultTagDto.references, + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultTagDto(model?: XTagDto) { + return isSameObject(prepareTagDtoFields(model), defaultTagDto); +} + +/** + * Model Type Guard ... + */ +export const isXTagDto = typeGuard(['id', 'tag']); + +/** + * Tag Dto to Tag Entity ... + * + * @param value + * @returns + */ +export function tagDto2Entity(value: XTagDto) { + // + let result: XTagEntity = undefined; + + // + if (!isNullOrUndefined(value) && isXTagDto(value)) { + // + const references = references2String(value.references); + result = { + id: value.id, + tag: value.tag, + references, + }; + } + + // + return result; +} + +/** + * Tag Entity to Tag Dto ... + * + * @param value + * @returns + */ +export function tagEntity2Dto(value: XTagEntity) { + // + let result: XTagDto = undefined; + + // + if (!isNullOrUndefined(value) && isXTagDto(value)) { + // + const references = parseXReferences(value.references); + result = { + id: value.id, + tag: value.tag, + references, + }; + } + + // + return result; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.entity.push.service.ts b/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.entity.push.service.ts new file mode 100644 index 0000000..9f16f94 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.entity.push.service.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; +import { XTagEntity } from '../models/x-tag.dto'; +import { XBaseEntityPushService } from 'x-framework-push-service'; +import { HttpTransportType, ITransport } from '@microsoft/signalr'; + +@Injectable({ + providedIn: 'root', +}) +export class XTagEntityPushService extends XBaseEntityPushService { + // + //#region Props ... + //#endregion + + // + //#region Abstracts ... + hubName(): string { + return 'tagEntityHub'; + } + + requiredAccessToken(): boolean { + return true; + } + + transportType(): HttpTransportType | ITransport { + return HttpTransportType.LongPolling; + } + + registerSubjects(): void { + super.registerSubjects(); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.entity.service.ts b/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.entity.service.ts new file mode 100644 index 0000000..0a621b4 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.entity.service.ts @@ -0,0 +1,39 @@ +import { Router } from '@angular/router'; +import { XTagEntity } from '../models/x-tag.dto'; +import { HttpClient } from '@angular/common/http'; +import { Inject, Injectable } from '@angular/core'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XBaseEntityService } from '../../base/x-base-entity.service'; +import { X_API_CONFIG, XApiConfiguration } from 'x-framework-identity-sdk'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; + +/** + * Provides all Entity Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XTagEntityService extends XBaseEntityService< + XTagEntity, + string +> { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.TagsEntity, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.provider.service.ts b/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.provider.service.ts new file mode 100644 index 0000000..2c71ea9 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tags/services/x-tag.provider.service.ts @@ -0,0 +1,654 @@ +import { + toArray, + hasChild, + XValidators, + XOneOrManyType, + isNullOrEmptyString, +} from 'x-framework-core'; +import { + HttpEvent, + HttpParams, + HttpClient, + HttpHeaders, + HttpResponse, +} from '@angular/common/http'; +import { + XQueryDto, + X_API_CONFIG, + XBaseApiService, + XQueryResultDto, + XApiConfiguration, +} from 'x-framework-identity-sdk'; +import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; +import { XTagDto } from '../models/x-tag.dto'; +import { Inject, Injectable } from '@angular/core'; +import { fillRouteParams } from '../../tools/x-route.tools'; +import { XTagParam, XTagServiceRoute } from '../x-tag.typings'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; +import { applyConnectionIdToHeader } from '../../typings/x-push-provider.typings'; + +/** + * Provides all Provider Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XTagProviderService extends XBaseApiService { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super(XApiEndPoint.TagsService, true, true, httpClient, config, apiConfig); + } + //#endregion + + // + //#region Actions ... + // + //#region Add ... + /** + * Add Model ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public add( + model: XTagDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public add( + model: XTagDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public add( + model: XTagDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public add( + model: XTagDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.tag); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XTagServiceRoute.Add); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Update ... + /** + * Update Model ... + * + * @param id + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public update( + id: number, + model: XTagDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public update( + id: number, + model: XTagDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public update( + id: number, + model: XTagDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public update( + id: number, + model: XTagDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.tag); + + // + if (model.id !== id) { + model.id = id; + } + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTagServiceRoute.Update), + // + // Params ... + [ + { + key: XTagParam.Id, + value: id.toString(), + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Remove ... + /** + * Remove Model ... + * + * @param id + * @param connectionId + * @param observe + * @param reportProgress + */ + public remove( + id: number, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public remove( + id: number, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public remove( + id: number, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public remove( + id: number, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + this.getActionRoute(XTagServiceRoute.Remove), + [ + { + key: XTagParam.Id, + value: id.toString(), + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Get ... + /** + * Get Specified Model ... + */ + public get( + id: number, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public get( + id: number, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public get( + id: number, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public get( + id: number, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTagServiceRoute.Get), + // + // Params ... + [ + { + key: XTagParam.Id, + value: id.toString(), + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetTag ... + /** + * Get Specified Model by Providing Label ... + */ + public getTag( + tag: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public getTag( + tag: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public getTag( + tag: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public getTag( + tag: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(tag); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tag to Params ... + params = this.addCustomParam(params, { + key: XTagParam.Tag, + value: tag + }); + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = this.getActionRoute(XTagServiceRoute.GetTag); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region All ... + /** + * Retrieve all Exists Models ... + * + * @param observe + * @param reportProgress + */ + public all( + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public all( + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public all( + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public all( + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XTagServiceRoute.All); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region FindOne ... + /** + * Detect Specified Model by Providing Label Query ... + */ + public findOne( + query: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public findOne( + query: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public findOne( + query: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public findOne( + query: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tag to Params ... + params = this.addCustomParam(params, { + key: XTagParam.Query, + value: query + }); + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = this.getActionRoute(XTagServiceRoute.FindOne); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region FindMany ... + /** + * Detect Specified Models by Providing Label Query ... + */ + public findMany( + query: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public findMany( + query: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public findMany( + query: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public findMany( + query: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tag to Params ... + params = this.addCustomParam(params, { + key: XTagParam.Query, + value: query + }); + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = this.getActionRoute(XTagServiceRoute.FindMany); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Query ... + /** + * Query Model ... + * + * @param query + * @param observe + * @param reportProgress + */ + public query( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public query( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public query( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public query( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XTagServiceRoute.Query); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tags/x-tag.services.ts b/projects/x-saherelm-api-sdk/src/lib/tags/x-tag.services.ts new file mode 100644 index 0000000..a5bf972 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tags/x-tag.services.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { XTagEntityService } from './services/x-tag.entity.service'; +import { XTagProviderService } from './services/x-tag.provider.service'; +import { XTagEntityPushService } from './services/x-tag.entity.push.service'; + +/** + * Export All Provided Tag related Services ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XTagServices { + // + //#region Constructor ... + public constructor( + public tagEntityService: XTagEntityService, + public tagProviderService: XTagProviderService, + public tagEntityPushService: XTagEntityPushService + ) {} + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tags/x-tag.typings.ts b/projects/x-saherelm-api-sdk/src/lib/tags/x-tag.typings.ts new file mode 100644 index 0000000..cd2d957 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tags/x-tag.typings.ts @@ -0,0 +1,23 @@ +/** + * All Available EndPoint Routes ... + */ +export enum XTagServiceRoute { + Add = '', + All = 'All', + Get = '{id}', + Update = '{id}', + Remove = '{id}', + Query = 'Query', + GetTag = 'GetTag', + FindOne = 'FindOne', + FindMany = 'FindMany', +} + +/** + * All Params Which Used in Related Services ... + */ +export enum XTagParam { + Id = 'id', + Tag = 'tag', + Query = 'query' +} diff --git a/projects/x-saherelm-api-sdk/src/lib/terms/services/x-terms.provider.service.ts b/projects/x-saherelm-api-sdk/src/lib/terms/services/x-terms.provider.service.ts new file mode 100644 index 0000000..7f2fe1a --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/terms/services/x-terms.provider.service.ts @@ -0,0 +1,507 @@ +import { + HttpEvent, + HttpClient, + HttpParams, + HttpHeaders, + HttpResponse, +} from '@angular/common/http'; +import { + X_API_CONFIG, + XBaseApiService, + XApiConfiguration, +} from 'x-framework-identity-sdk'; +import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; +import { Inject, Injectable } from '@angular/core'; +import { XLocale, XValidators } from 'x-framework-core'; +import { fillRouteParams } from '../../tools/x-route.tools'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XTermsParam, XTermsServiceRoute } from '../x-terms.typings.dto'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; +import { applyConnectionIdToHeader } from '../../typings/x-push-provider.typings'; + +/** + * Provides all Provider Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XTermsProviderService extends XBaseApiService { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.TermsAndConditions, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion + + // + //#region Actions ... + // + //#region Get ... + /** + * Get Specified Languages Terms and Conditions ... + * + * @param language + * @param observe + * @param reportProgress + */ + public get( + language: XLocale | string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public get( + language: XLocale | string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public get( + language: XLocale | string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public get( + language: XLocale | string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTermsServiceRoute.Get), + // + // Params ... + [ + { + key: XTermsParam.Language, + value: language, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Languages ... + /** + * Get Languages Lists which Contains Terms and Conditions ... + * + * @param observe + * @param reportProgress + */ + public getLanguages( + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public getLanguages( + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public getLanguages( + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public getLanguages( + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = this.getActionRoute(XTermsServiceRoute.Languages); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Has ... + /** + * Check Specified Languages Terms and Conditions Exists or not ... + * + * @param language + * @param observe + * @param reportProgress + */ + public has( + language: XLocale | string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public has( + language: XLocale | string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public has( + language: XLocale | string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public has( + language: XLocale | string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTermsServiceRoute.Has), + // + // Params ... + [ + { + key: XTermsParam.Language, + value: language, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Add ... + /** + * Add Terms and Conditions For Spevified Language ... + * + * @param language + * @param terms + * @param connectionId + * @param observe + * @param reportProgress + */ + public add( + language: XLocale | string, + terms: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public add( + language: XLocale | string, + terms: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public add( + language: XLocale | string, + terms: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public add( + language: XLocale | string, + terms: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(terms); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTermsServiceRoute.Add), + // + // Params ... + [ + { + key: XTermsParam.Language, + value: language, + }, + ] + ); + + // + // Add terms Query String ... + params = this.addCustomParam(params, { + key: XTermsParam.Terms, + value: terms, + }); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Update ... + /** + * Update Terms and Conditions For Spevified Language ... + * + * @param language + * @param terms + * @param connectionId + * @param observe + * @param reportProgress + */ + public update( + language: XLocale | string, + terms: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public update( + language: XLocale | string, + terms: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public update( + language: XLocale | string, + terms: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public update( + language: XLocale | string, + terms: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(terms); + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTermsServiceRoute.Update), + // + // Params ... + [ + { + key: XTermsParam.Language, + value: language, + }, + ] + ); + + // + // Add terms Query String ... + params = this.addCustomParam(params, { + key: XTermsParam.Terms, + value: terms, + }); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Remove ... + /** + * Remove Terms and Conditions For Spevified Language ... + * + * @param language + * @param connectionId + * @param observe + * @param reportProgress + */ + public remove( + language: XLocale | string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public remove( + language: XLocale | string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public remove( + language: XLocale | string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public remove( + language: XLocale | string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(language); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint ... + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XTermsServiceRoute.Remove), + // + // Params ... + [ + { + key: XTermsParam.Language, + value: language, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/terms/services/x-terms.push.service.ts b/projects/x-saherelm-api-sdk/src/lib/terms/services/x-terms.push.service.ts new file mode 100644 index 0000000..7a00b6e --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/terms/services/x-terms.push.service.ts @@ -0,0 +1,169 @@ +import { Subject } from 'rxjs'; +import { + XBasePushService, + XBaseEntityPushAction, + IXPushServiceTokenFetcher, + XFrameworkPushServiceConfig, + X_FRAMEWORK_PUSH_SERVICE_CONFIG, + X_FRAMEWORK_PUSH_SERVICE_TOKEN_FETCHER, +} from 'x-framework-push-service'; +import { parseJson } from 'x-framework-core'; +import { Inject, Injectable, Optional } from '@angular/core'; +import { XStringDto } from '../../strings/models/x-string.dto'; +import { HttpTransportType, ITransport } from '@microsoft/signalr'; + +@Injectable({ + providedIn: 'root', +}) +export class XTermsPushService extends XBasePushService { + // + //#region Props ... + onTermsAdded$ = new Subject<{ + model: XStringDto; + actorId: string; + }>(); + onTermsDeleted$ = new Subject<{ + model: XStringDto; + actorId: string; + }>(); + onTermsUpdated$ = new Subject<{ + model: XStringDto; + actorId: string; + }>(); + //#endregion + + // + //#region Constructor ... + constructor( + @Inject(X_FRAMEWORK_PUSH_SERVICE_CONFIG) + public config: XFrameworkPushServiceConfig, + @Optional() + @Inject(X_FRAMEWORK_PUSH_SERVICE_TOKEN_FETCHER) + public tokenFetcher?: IXPushServiceTokenFetcher + ) { + super(config, tokenFetcher); + } + //#endregion + + // + //#region Abstraction ... + hubName(): string { + return 'termsHub'; + } + + requiredAccessToken(): boolean { + return true; + } + + transportType(): HttpTransportType | ITransport { + return HttpTransportType.LongPolling; + } + + registerSubjects(): void { + super.registerSubjects(); + + // + this.onTermsAdded((model: XStringDto, actorId: string) => { + this.onTermsAdded$.next({ model, actorId }); + }); + + // + this.onTermsDeleted((model: XStringDto, actorId: string) => { + this.onTermsDeleted$.next({ model, actorId }); + }); + + // + this.onTermsUpdated((model: XStringDto, actorId: string) => { + this.onTermsUpdated$.next({ model, actorId }); + }); + } + //#endregion + + // + //#region Event Listeners ... + // + //#region Onners ... + /** + * Register Terms Added Event Listener ... + * + * @param callback + */ + public onTermsAdded(callback: (model: XStringDto, actorId: string) => any) { + // + this.on(XBaseEntityPushAction.Add, (modelJson: string, actorId: string) => { + // + const model = parseJson(modelJson); + callback(model, actorId); + }); + } + + /** + * Register Terms Deleted Event Listener ... + * + * @param callback + */ + public onTermsDeleted(callback: (model: XStringDto, actorId: string) => any) { + // + this.on( + XBaseEntityPushAction.Delete, + (modelJson: string, actorId: string) => { + // + const model = parseJson(modelJson); + callback(model, actorId); + } + ); + } + + /** + * Register Terms Updated Event Listener ... + * + * @param callback + */ + public onTermsUpdated(callback: (model: XStringDto, actorId: string) => any) { + // + this.on( + XBaseEntityPushAction.Update, + (modelJson: string, actorId: string) => { + // + const model = parseJson(modelJson); + callback(model, actorId); + } + ); + } + //#endregion + + // + //#region Offers ... + /** + * UnRegister Added Event Listener ... + * + * @param callback + */ + public offTermsAdded(callback?: (model: XStringDto, actorId: string) => any) { + this.off(XBaseEntityPushAction.Add, callback); + } + + /** + * UnRegister Deleted Event Listener ... + * + * @param callback + */ + public offTermsDeleted( + callback?: (model: XStringDto, actorId: string) => any + ) { + this.off(XBaseEntityPushAction.Delete, callback); + } + + /** + * UnRegister Updated Event Listener ... + * + * @param callback + */ + public offTermsUpdated( + callback?: (model: XStringDto, actorId: string) => any + ) { + this.off(XBaseEntityPushAction.Update, callback); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/terms/x-terms.service.ts b/projects/x-saherelm-api-sdk/src/lib/terms/x-terms.service.ts new file mode 100644 index 0000000..968f319 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/terms/x-terms.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { XTermsPushService } from './services/x-terms.push.service'; +import { XTermsProviderService } from './services/x-terms.provider.service'; + +/** + * Export All Provided Terms related Services ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XTermsServices { + // + //#region Constructor ... + public constructor( + public termsPushService: XTermsPushService, + public termsProviderService: XTermsProviderService + ) {} + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/terms/x-terms.typings.dto.ts b/projects/x-saherelm-api-sdk/src/lib/terms/x-terms.typings.dto.ts new file mode 100644 index 0000000..7613991 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/terms/x-terms.typings.dto.ts @@ -0,0 +1,19 @@ +/** + * All Available EndPoint Routes ... + */ +export enum XTermsServiceRoute { + Add = 'Terms/{language}', + Get = 'Terms/{language}', + Update = 'Terms/{language}', + Remove = 'Terms/{language}', + Has = 'Terms/{language}/Has', + Languages = 'Terms/Languages', +} + +/** + * All Params Which Used in Related Services ... + */ +export enum XTermsParam { + Terms = 'terms', + Language = 'language', +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tokens/x-injectable-tokens.ts b/projects/x-saherelm-api-sdk/src/lib/tokens/x-injectable-tokens.ts new file mode 100644 index 0000000..fd87579 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tokens/x-injectable-tokens.ts @@ -0,0 +1,6 @@ +import { InjectionToken } from '@angular/core'; +import { XSaherElmApiSDKConfig } from '../config/x-saherelm-api-sdk.config'; + +export const X_SAHERELM_API_SDK_CONFIG = new InjectionToken( + 'x_config' +); diff --git a/projects/x-saherelm-api-sdk/src/lib/tools/x-model.tools.ts b/projects/x-saherelm-api-sdk/src/lib/tools/x-model.tools.ts new file mode 100644 index 0000000..dff9dba --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tools/x-model.tools.ts @@ -0,0 +1,22 @@ +import { isArray, isObject } from 'x-framework-core'; + +/** + * since for better handling soft deleted in database from api side the deleted + * property added to all XEntities, for better comparing objects we have to delete it. + * this method do this for us ... + * + * @param model the input object + * @returns clear object + */ +export function prepareModel(model: T) { + // + if (!isObject(model) || isArray(model)) { + return model; + } + + // + delete (model as any)['deleted']; + + // + return model; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tools/x-role.tools.ts b/projects/x-saherelm-api-sdk/src/lib/tools/x-role.tools.ts new file mode 100644 index 0000000..a1338bf --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tools/x-role.tools.ts @@ -0,0 +1,286 @@ +import { + toArray, + hasChild, + XExceptionIDs, + throwException, + XOneOrManyType, +} from 'x-framework-core'; +import { XUserProfileDto } from 'x-framework-identity-sdk'; +import { XUserRoleInfo, XAvailableRoles } from '../typings/x-role.typings'; + +export function toRoleInfo(user: XUserProfileDto): XUserRoleInfo { + // + if (!user) { + return null; + } + + // + const result: XUserRoleInfo = { + isAdmin: hasChild(user.roles) && user.roles.includes(XAvailableRoles.Admin), + isResponsibleManager: + hasChild(user.roles) && + user.roles.includes(XAvailableRoles.ResponsibleManager), + isJournalist: + hasChild(user.roles) && user.roles.includes(XAvailableRoles.Journalist), + isChiefClerk: + hasChild(user.roles) && user.roles.includes(XAvailableRoles.ChiefClerk), + isChiefClerkAssistant: + hasChild(user.roles) && + user.roles.includes(XAvailableRoles.ChiefClerkAssistant), + isActuary: + hasChild(user.roles) && user.roles.includes(XAvailableRoles.Actuary), + isActuaryAssistant: + hasChild(user.roles) && + user.roles.includes(XAvailableRoles.ActuaryAssistant), + isReporter: + hasChild(user.roles) && user.roles.includes(XAvailableRoles.Reporter), + isReporterAssistant: + hasChild(user.roles) && + user.roles.includes(XAvailableRoles.ReporterAssistant), + isAgent: hasChild(user.roles) && user.roles.includes(XAvailableRoles.Agent), + isUser: hasChild(user.roles) && user.roles.includes(XAvailableRoles.User), + }; + + // + return result; +} + +export function toRoleInfoByRoles(roles: string[]): XUserRoleInfo { + // + if (!hasChild(roles)) { + return null; + } + + // + const result: XUserRoleInfo = { + isAdmin: hasChild(roles) && roles.includes(XAvailableRoles.Admin), + isResponsibleManager: + hasChild(roles) && roles.includes(XAvailableRoles.ResponsibleManager), + isJournalist: hasChild(roles) && roles.includes(XAvailableRoles.Journalist), + isChiefClerk: hasChild(roles) && roles.includes(XAvailableRoles.ChiefClerk), + isChiefClerkAssistant: + hasChild(roles) && roles.includes(XAvailableRoles.ChiefClerkAssistant), + isActuary: hasChild(roles) && roles.includes(XAvailableRoles.Actuary), + isActuaryAssistant: + hasChild(roles) && roles.includes(XAvailableRoles.ActuaryAssistant), + isReporter: hasChild(roles) && roles.includes(XAvailableRoles.Reporter), + isReporterAssistant: + hasChild(roles) && roles.includes(XAvailableRoles.ReporterAssistant), + isAgent: hasChild(roles) && roles.includes(XAvailableRoles.Agent), + isUser: hasChild(roles) && roles.includes(XAvailableRoles.User), + }; + + // + return result; +} + +export function getTopRoleByRoleInfo(roleInfo: XUserRoleInfo) { + // + if (!roleInfo) { + throwException(XExceptionIDs.InvalidArgs); + } + + // + if (roleInfo.isAdmin) { + return XAvailableRoles.Admin; + } else if (roleInfo.isResponsibleManager) { + return XAvailableRoles.ResponsibleManager; + } else if (roleInfo.isJournalist) { + return XAvailableRoles.Journalist; + } else if (roleInfo.isChiefClerk) { + return XAvailableRoles.ChiefClerk; + } else if (roleInfo.isChiefClerkAssistant) { + return XAvailableRoles.ChiefClerkAssistant; + } else if (roleInfo.isActuary) { + return XAvailableRoles.Actuary; + } else if (roleInfo.isActuaryAssistant) { + return XAvailableRoles.ActuaryAssistant; + } else if (roleInfo.isReporter) { + return XAvailableRoles.Reporter; + } else if (roleInfo.isReporterAssistant) { + return XAvailableRoles.ReporterAssistant; + } else if (roleInfo.isAgent) { + return XAvailableRoles.Agent; + } else if (roleInfo.isUser) { + return XAvailableRoles.User; + } else { + return null; + } +} + +export function getTopRoleByRoles(roles: string[]) { + // + const roleInfo = toRoleInfoByRoles(roles); + if (!roleInfo) { + return null; + } + + // + return getTopRoleByRoleInfo(roleInfo); +} + +export function getTopRoleByProfile(user: XUserProfileDto) { + // + const roleInfo = toRoleInfo(user); + if (!roleInfo) { + return null; + } + + // + return getTopRoleByRoleInfo(roleInfo); +} + +export function checkIsInRoleByInfo( + roles: XOneOrManyType, + roleInfo: XUserRoleInfo +): boolean { + // + let result = false; + + // + // Normalize Roles ... + const normalRoles = toArray(roles); + + // + for (const role of normalRoles) { + switch (role) { + // + case XAvailableRoles.Admin: + result = result || roleInfo.isAdmin; + break; + + // + case XAvailableRoles.ResponsibleManager: + result = result || roleInfo.isResponsibleManager; + break; + + // + case XAvailableRoles.Journalist: + result = result || roleInfo.isJournalist; + break; + + // + case XAvailableRoles.ChiefClerk: + result = result || roleInfo.isChiefClerk; + break; + + // + case XAvailableRoles.ChiefClerkAssistant: + result = result || roleInfo.isChiefClerkAssistant; + break; + + // + case XAvailableRoles.Actuary: + result = result || roleInfo.isActuary; + break; + + // + case XAvailableRoles.ActuaryAssistant: + result = result || roleInfo.isActuaryAssistant; + break; + + // + case XAvailableRoles.Reporter: + result = result || roleInfo.isReporter; + break; + + // + case XAvailableRoles.ReporterAssistant: + result = result || roleInfo.isReporterAssistant; + break; + + // + case XAvailableRoles.Agent: + result = result || roleInfo.isAgent; + break; + + // + case XAvailableRoles.User: + result = result || roleInfo.isUser; + break; + + // + default: + result = result || false; + break; + } + } + + // + return result; +} + +export function checkIsInRoleByUser( + role: XAvailableRoles, + user: XUserProfileDto +): boolean { + // + // Validate Args ... + if (!role || !user) { + return false; + } + + // + const roleInfo = toRoleInfo(user); + if (!roleInfo) { + return false; + } + + // + switch (role) { + // + case XAvailableRoles.Admin: + return roleInfo.isAdmin; + + // + case XAvailableRoles.ResponsibleManager: + return roleInfo.isResponsibleManager; + + // + case XAvailableRoles.Journalist: + return roleInfo.isJournalist; + + // + case XAvailableRoles.ChiefClerk: + return roleInfo.isChiefClerk; + + // + case XAvailableRoles.ChiefClerkAssistant: + return roleInfo.isChiefClerkAssistant; + + // + case XAvailableRoles.Actuary: + return roleInfo.isActuary; + + // + case XAvailableRoles.ActuaryAssistant: + return roleInfo.isActuaryAssistant; + + // + case XAvailableRoles.Reporter: + return roleInfo.isReporter; + + // + case XAvailableRoles.ReporterAssistant: + return roleInfo.isReporterAssistant; + + // + case XAvailableRoles.Agent: + return roleInfo.isAgent; + + // + case XAvailableRoles.User: + return roleInfo.isUser; + + // + default: + return false; + } +} + +export function extractAvaialableRoles() { + // + const AllRoles = Object.assign({}, XAvailableRoles); + let result = Object.values(AllRoles); + return result; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/tools/x-route.tools.ts b/projects/x-saherelm-api-sdk/src/lib/tools/x-route.tools.ts new file mode 100644 index 0000000..e2eb480 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/tools/x-route.tools.ts @@ -0,0 +1,38 @@ +import { + hasChild, + XKeyValue, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; + +/** + * Prepare a route by replacing it's params by providing values ... + */ +export function fillRouteParams( + route: string, + params?: Array> +) { + // + let result = ''; + + // + // Validate ... + if (isNullOrEmptyString(route)) { + return result; + } + + // + // Check Params Has Child ... + if (!isNullOrUndefined(params) && hasChild(params)) { + // + result = route; + for (let param of params) { + // + const key = `{${param.key}}`; + result = result.replace(key, param.value); + } + } + + // + return result; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/typings/x-endpoint.typings.ts b/projects/x-saherelm-api-sdk/src/lib/typings/x-endpoint.typings.ts new file mode 100644 index 0000000..648cb48 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/typings/x-endpoint.typings.ts @@ -0,0 +1,91 @@ +// +//#region Custom Header and Params ... +export enum XCHeader { + Role = 'role', + ForceRole = 'forceRole', +} +//#endregion + +// +//#region Params ... +/** + * Params Usually Used in Query Strings ... + */ +export enum XBaseParams { + XId = 'id', + XIds = 'ids', + XSoftDelete = 'softDelete', + XIgnoreSoftDeleteds = 'ignoreSoftDeleteds', +} + +/** + * prepare all Route Params which used in Account Services Endpoints ... + */ +export enum XBaseEndPointParam { + XId = '{xId}', + XIds = '{xIds}', + XHash = '{xHash}', + XDate = '{xDate}', + XQuery = '{xQuery}', + XTitle = '{xTitle}', + XIdentifier = '{xIdentifier}', + XConnectionID = '{xConnectionId}', + XConnectionIDs = '{xConnectionIds}', + XUserSelectByParam = '{xUserSelectByParam}', + XIgnoreSoftDeleteds = '{xIgnoreSoftDeleteds}', + XUserSelectByParams = '{xUserSelectByParams}', +} +export type XBaseEndPointParams = keyof typeof XBaseEndPointParam; + +/** + * All Commonly Used EndPoints Actions ... + */ +export enum XBaseEndPointAction { + // + // TODO: Complete this ... + Get = '{xId}', + GetAll = '', + FindOne = 'FindOne/{xQuery}', + FindMany = 'FindMany/{xQuery}', + Query = 'Query', + RequestPage = 'RequestPage', + Add = '', + AddOrUpdate = 'AddOrUpdate', + AddMany = 'AddMany', + Update = '{xId}', + UpdateMany = 'UpdateMany', + IsExists = '{xId}/IsExists', + Remove = '{xId}', + RemoveMany = 'RemoveMany', +} +export type XBaseEndPointActions = keyof typeof XBaseEndPointAction; +//#endregion + +// +//#region Api EndPoints ... +/** + * Represent all API End Points ... + */ +export enum XApiEndPoint { + TagsEntity = 'Entities/Tags', + TagsService = 'Services/Tags', + FilesEntity = 'Entities/Files', + FilesService = 'Services/Files', + Configurations = 'Configurations', + StringsEntity = 'Entities/Strings', + StringsService = 'Services/Strings', + WebinarsEntity = 'Entities/Webinars', + WebinarsService = 'Services/Webinars', + TermsAndConditions = 'Configurations', +} + +export declare type XApiEndPoints = keyof typeof XApiEndPoint | string; +//#endregion + +// +//#region Configuration ... +export enum XConfigurationEndPoint { +} + +export type XConfigurationEndPoints = keyof typeof XConfigurationEndPoint; +//#endregion diff --git a/projects/x-saherelm-api-sdk/src/lib/typings/x-push-provider.typings.ts b/projects/x-saherelm-api-sdk/src/lib/typings/x-push-provider.typings.ts new file mode 100644 index 0000000..8b2419f --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/typings/x-push-provider.typings.ts @@ -0,0 +1,33 @@ +import { HttpHeaders } from '@angular/common/http'; +import { isNullOrEmptyString, isNullOrUndefined } from 'x-framework-core'; + +export enum XPushHeaderKeys { + ConnectionId = 'requestID', +} + +/** + * add Connection Id to Headers ... + * + * @param connectionId user connection id ... + * @param headers an instance of HttpHeaders ... + * + * @returns HttpHeaders instance + */ +export function applyConnectionIdToHeader( + connectionId?: string, + headers?: HttpHeaders +) { + // + // New Instance of Headers if Not provided ... + if (isNullOrUndefined(headers)) { + headers = new HttpHeaders(); + } + + // + if (!isNullOrEmptyString(connectionId)) { + headers = headers.set(XPushHeaderKeys.ConnectionId, connectionId); + } + + // + return headers; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/typings/x-role.typings.ts b/projects/x-saherelm-api-sdk/src/lib/typings/x-role.typings.ts new file mode 100644 index 0000000..20c0c81 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/typings/x-role.typings.ts @@ -0,0 +1,27 @@ +export enum XAvailableRoles { + Admin = 'admin', + ResponsibleManager = 'responsible_manager', + Journalist = 'journalist', + ChiefClerk = 'chief_clerk', + ChiefClerkAssistant = 'chief_clerk_assistant', + Actuary = 'actuary', + ActuaryAssistant = 'actuary_assistant', + Reporter = 'reporter', + ReporterAssistant = 'reporter_assistant', + Agent = 'agent', + User = 'user', +} + +export interface XUserRoleInfo { + isAdmin: boolean; + isResponsibleManager: boolean; + isJournalist: boolean; + isChiefClerk: boolean; + isChiefClerkAssistant: boolean; + isActuary: boolean; + isActuaryAssistant: boolean; + isReporter: boolean; + isReporterAssistant: boolean; + isAgent: boolean; + isUser: boolean; +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/models/x-webinar.dto.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/models/x-webinar.dto.ts new file mode 100644 index 0000000..d7bd102 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/models/x-webinar.dto.ts @@ -0,0 +1,199 @@ +import { + XBaseDto, + typeGuard, + isSameObject, + XBaseNumberIDDto, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; +import { + XResourceDto, + prepareResourceDtoFields, +} from '../../strings/models/x-string.dto'; +import { preparePersonDtoFields, XPersonDto } from '../../models/x-person.dto'; + +/** + * Describe Webinar Types ... + */ +export enum XWebinarType { + Public = 0, + Private = 1, +} + +export function ToWebinarType(index: number) { + // + if (index == 0) { + return XWebinarType.Public; + } else if (index == 1) { + return XWebinarType.Private; + } + + // + return undefined; +} + +/** + * Represent a Webinar Model ... + */ +export interface XWebinarDto extends XBaseDto { + id: string; + ownerId: string; + createdOn: Date; + enabled: boolean; + type: XWebinarType; + owner?: XPersonDto; + title: XResourceDto; + description: XResourceDto; +} + +/** + * Default Model ... + */ +export const defaultWebinarDto: XWebinarDto = { + id: '', + ownerId: '', + enabled: false, + type: undefined, + owner: undefined, + title: undefined, + createdOn: undefined, + description: undefined, +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function prepareWebinarDtoFields(model?: XWebinarDto) { + // + if (isNullOrUndefined(model)) { + model = { + ...defaultWebinarDto, + }; + } + + // + model = { + id: isNullOrEmptyString(model.id) ? defaultWebinarDto.id : model.id, + type: isNullOrUndefined(model.type) ? defaultWebinarDto.type : model.type, + enabled: isNullOrUndefined(model.enabled) + ? defaultWebinarDto.enabled + : model.enabled, + ownerId: isNullOrEmptyString(model.ownerId) + ? defaultWebinarDto.ownerId + : model.ownerId, + createdOn: isNullOrUndefined(model.createdOn) + ? defaultWebinarDto.createdOn + : model.createdOn, + owner: isNullOrUndefined(model.owner) + ? defaultWebinarDto.owner + : preparePersonDtoFields(model.owner), + title: isNullOrUndefined(model.title) + ? defaultWebinarDto.title + : prepareResourceDtoFields(model.title), + description: isNullOrUndefined(model.description) + ? defaultWebinarDto.description + : prepareResourceDtoFields(model.description), + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultWebinarModel(model?: XWebinarDto) { + return isSameObject(prepareWebinarDtoFields(model), defaultWebinarDto); +} + +/** + * Webinar Subscriber Model ... + */ +export interface XWebinarSubscriberDto extends XBaseNumberIDDto { + webinarId: string; + subscribedOn: Date; + subscriberId: string; + subscriber: XPersonDto; +} + +/** + * Default Model ... + */ +export const defaultWebinarSubscriberDto: XWebinarSubscriberDto = { + id: undefined, + webinarId: '', + subscriberId: '', + subscriber: undefined, + subscribedOn: undefined, +}; + +/** + * Prepare Model Fields ... + * + * @param model + * @returns + */ +export function prepareWebinarSubscriberDtoFields( + model?: XWebinarSubscriberDto +) { + // + if (isNullOrUndefined(model)) { + model = { + ...defaultWebinarSubscriberDto, + }; + } + + // + model = { + id: + isNullOrUndefined(model.id) || model.id <= 0 + ? defaultWebinarSubscriberDto.id + : model.id, + webinarId: isNullOrEmptyString(model.webinarId) + ? defaultWebinarSubscriberDto.webinarId + : model.webinarId, + subscriberId: isNullOrEmptyString(model.subscriberId) + ? defaultWebinarSubscriberDto.subscriberId + : model.subscriberId, + subscribedOn: isNullOrUndefined(model.subscribedOn) + ? defaultWebinarSubscriberDto.subscribedOn + : model.subscribedOn, + subscriber: isNullOrUndefined(model.subscriber) + ? defaultWebinarSubscriberDto.subscriber + : preparePersonDtoFields(model.subscriber), + }; + + // + return model; +} + +/** + * Check Model is Default or not ... + * + * @param model + * @returns + */ +export function isDefaultWebinarSubscriberDto(model?: XWebinarSubscriberDto) { + return isSameObject( + prepareWebinarSubscriberDtoFields(model), + defaultWebinarSubscriberDto + ); +} + +/** + * Model Type Guard ... + */ +export const isXWebinarDto = typeGuard([ + 'id', + 'ownerId', + 'type', + 'createdOn', + 'description', + 'title', +]); diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.entity.push.service.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.entity.push.service.ts new file mode 100644 index 0000000..6e22bf5 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.entity.push.service.ts @@ -0,0 +1,167 @@ +import { Subject } from 'rxjs'; +import { Injectable } from '@angular/core'; +import { isNullOrUndefined, parseJson } from 'x-framework-core'; +import { XWebinarEntityPushAction } from '../x-webinar.typings'; +import { XBaseEntityPushService } from 'x-framework-push-service'; +import { HttpTransportType, ITransport } from '@microsoft/signalr'; +import { XWebinarDto, XWebinarSubscriberDto } from '../models/x-webinar.dto'; + +@Injectable({ + providedIn: 'root', +}) +export class XWebinarEntityPushService extends XBaseEntityPushService { + // + //#region Props ... + onSubscribed$ = new Subject<{ + model: XWebinarSubscriberDto; + actorId: string; + }>(); + onUnsubscribed$ = new Subject<{ + model: XWebinarSubscriberDto; + actorId: string; + }>(); + //#endregion + + // + //#region Abstracts ... + hubName(): string { + return 'webinarEntityHub'; + } + + requiredAccessToken(): boolean { + return true; + } + + transportType(): HttpTransportType | ITransport { + return HttpTransportType.LongPolling; + } + + registerSubjects(): void { + super.registerSubjects(); + + // + this.onSubscribed((model: XWebinarSubscriberDto, actorId: string) => { + this.onSubscribed$.next({ model, actorId }); + }); + + // + this.onUnsubscribed((model: XWebinarSubscriberDto, actorId: string) => { + this.onUnsubscribed$.next({ model, actorId }); + }); + } + //#endregion + + // + //#region Actions ... + /** + * Fire New Subscriber Action ... + * + * @param model + * @returns + */ + public async subscribe(model: XWebinarSubscriberDto) { + // + // Validate ... + let isValid = !isNullOrUndefined(model); + if (!isValid) { + return; + } + + // + await this.invoke( + XWebinarEntityPushAction.Subscribe, + JSON.stringify(model) + ); + } + + /** + * Fire Unsubscribe Action ... + * + * @param model + * @returns + */ + public async unsubscribe(model: XWebinarSubscriberDto) { + // + // Validate ... + let isValid = !isNullOrUndefined(model); + if (!isValid) { + return; + } + + // + await this.invoke( + XWebinarEntityPushAction.Unsubscribe, + JSON.stringify(model) + ); + } + //#endregion + + // + //#region Event Listeners ... + // + //#region Onners ... + /** + * Register Subscribe Event Listener ... + * + * @param callback + */ + public onSubscribed( + callback: (model: XWebinarSubscriberDto, actorId: string) => any + ) { + // + this.on( + XWebinarEntityPushAction.Subscribe, + (modelJson: string, actorId: string) => { + // + const model = parseJson(modelJson); + callback(model, actorId); + } + ); + } + + /** + * Register Unsubscribe Event Listener ... + * + * @param callback + */ + public onUnsubscribed( + callback: (model: XWebinarSubscriberDto, actorId: string) => any + ) { + // + this.on( + XWebinarEntityPushAction.Unsubscribe, + (modelJson: string, actorId: string) => { + // + const model = parseJson(modelJson); + callback(model, actorId); + } + ); + } + //#endregion + + // + //#region Offers ... + /** + * UnRegister Subscribe Event Listener ... + * + * @param callback + */ + public offSubscribed( + callback?: (model: XWebinarSubscriberDto, actorId: string) => any + ) { + this.off(XWebinarEntityPushAction.Subscribe, callback); + } + + /** + * UnRegister Unsubscribe Event Listener ... + * + * @param callback + */ + public offUnsubscribed( + callback?: (model: XWebinarSubscriberDto, actorId: string) => any + ) { + this.off(XWebinarEntityPushAction.Unsubscribe, callback); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.entity.service.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.entity.service.ts new file mode 100644 index 0000000..f8fa1d0 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.entity.service.ts @@ -0,0 +1,39 @@ +import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { Inject, Injectable } from '@angular/core'; +import { XWebinarDto } from '../models/x-webinar.dto'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XBaseEntityService } from '../../base/x-base-entity.service'; +import { X_API_CONFIG, XApiConfiguration } from 'x-framework-identity-sdk'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; + +/** + * Provides all Entity Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XWebinarEntityService extends XBaseEntityService< + XWebinarDto, + string +> { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.WebinarsEntity, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.provider.service.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.provider.service.ts new file mode 100644 index 0000000..5a81fc7 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.provider.service.ts @@ -0,0 +1,1856 @@ +import { + toArray, + hasChild, + toFormData, + XValidators, + toListString, + XOneOrManyType, + isNullOrUndefined, + isNullOrEmptyString, +} from 'x-framework-core'; +import { + HttpEvent, + HttpClient, + HttpParams, + HttpHeaders, + HttpResponse, +} from '@angular/common/http'; +import { + XQueryDto, + X_API_CONFIG, + XBaseApiService, + XQueryResultDto, + XApiConfiguration, +} from 'x-framework-identity-sdk'; +import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; +import { Inject, Injectable } from '@angular/core'; +import { XFileDto } from '../../files/models/x-file.dto'; +import { fillRouteParams } from '../../tools/x-route.tools'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XWebinarParam, XWebinarServiceRoute } from '../x-webinar.typings'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XWebinarDto, XWebinarSubscriberDto } from '../models/x-webinar.dto'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; +import { applyConnectionIdToHeader } from '../../typings/x-push-provider.typings'; + +/** + * Provides all Provider Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XWebinarProviderService extends XBaseApiService { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.WebinarsService, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion + + // + //#region Webinar ... + // + //#region Create ... + /** + * Create Specified Described Webinars ... + * + * @param model + * @param tags + * @param files + * @param connectionId + * @param observe + * @param reportProgress + */ + public create( + model: XWebinarDto, + tags?: XOneOrManyType, + files?: XOneOrManyType, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public create( + model: XWebinarDto, + tags?: XOneOrManyType, + files?: XOneOrManyType, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public create( + model: XWebinarDto, + tags?: XOneOrManyType, + files?: XOneOrManyType, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public create( + model: XWebinarDto, + tags?: XOneOrManyType, + files?: XOneOrManyType, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotNull(model.title); + XValidators.validateNotEmpty(model.ownerId); + XValidators.validateNotNull(model.description); + + // + // Since Here we support Medias, must sent all Body as + // Form Data ... + let formData: FormData = new FormData(); + + // + // Add Model to FormData ... + formData = toFormData( + { ...model }, // Model ... + undefined, // Options ... + formData, // Exists FormData Using ... + undefined // Keys Prefix ... + ); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute( + XWebinarServiceRoute.CreateWebinar + ); + + // + // Handle Tags ... + if (!isNullOrUndefined(tags)) { + // + const tagsArr = toArray(tags); + if (hasChild(tagsArr)) { + // + const tagsListString = toListString(tagsArr); + if (!isNullOrEmptyString(tagsListString)) { + // + params = this.addCustomParam(params, { + key: XWebinarParam.Tags, + value: tagsListString, + }); + } + } + } + + // + // Handle Files ... + if (!isNullOrUndefined(files)) { + // + const filesArr = toArray(files); + if (hasChild(filesArr)) { + // + // Convert Files Array to Form Data ... + filesArr.forEach((f) => { + formData.append(XWebinarParam.Files, f, f.name); + }); + } + } + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, formData, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Update ... + /** + * Update Webinar ... + * + * @param model + * @param connectionId + * @param observe + * @param reportProgress + */ + public update( + model: XWebinarDto, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public update( + model: XWebinarDto, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public update( + model: XWebinarDto, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public update( + model: XWebinarDto, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(model); + XValidators.validateNotEmpty(model.id); + XValidators.validateNotNull(model.title); + XValidators.validateNotEmpty(model.ownerId); + XValidators.validateNotNull(model.description); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.UpdateWebinar), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: model.id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.put(endPointPath, model, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Remove ... + /** + * Remove Specified Webinar ... + * + * @param id + * @param connectionId + * @param observe + * @param reportProgress + */ + public remove( + id: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public remove( + id: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public remove( + id: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public remove( + id: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.RemoveWebinar), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Get ... + /** + * Get Specified Webinar ... + */ + public get( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public get( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public get( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public get( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + // headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.GetWebinar), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region All ... + /** + * Retrieve all Exists Webinars ... + * + * @param observe + * @param reportProgress + */ + public all( + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public all( + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public all( + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public all( + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute(XWebinarServiceRoute.GetWebinars); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Query ... + /** + * Query Webinars ... + * + * @param query + * @param observe + * @param reportProgress + */ + public query( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public query( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public query( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public query( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute( + XWebinarServiceRoute.QueryWebinars + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region QueryOwned ... + /** + * Query Owned Webinars ... + * + * @param query + * @param observe + * @param reportProgress + */ + public queryOwned( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public queryOwned( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public queryOwned( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public queryOwned( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute( + XWebinarServiceRoute.QueryOwnedWebinars + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region QueryJoinable ... + /** + * Query Joinable Webinars ... + * + * @param query + * @param observe + * @param reportProgress + */ + public queryJoinable( + query: XQueryDto, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public queryJoinable( + query: XQueryDto, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public queryJoinable( + query: XQueryDto, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public queryJoinable( + query: XQueryDto, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Preparing HttpParams ... + params = this.generateXQueryHttpParams(query); + + // + // Prepare Endpoint + const endPointPath = this.getActionRoute( + XWebinarServiceRoute.QueryJoinableWebinars + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Subscriber ... + // + //#region Subscribe ... + /** + * Subscribe a User to Webinar ... + * + * @param webinarId + * @param subscriberId + * @param connectionId + * @param observe + * @param reportProgress + */ + public subscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public subscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public subscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public subscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(webinarId); + XValidators.validateNotEmpty(subscriberId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.Subscribe), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + { + key: XWebinarParam.SubscriberId, + value: subscriberId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region Unsubscribe ... + /** + * Unsubscribe Specified User from a Specified Webinar ... + * + * @param webinarId + * @param subscriberId + * @param connectionId + * @param observe + * @param reportProgress + */ + public unsubscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public unsubscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public unsubscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public unsubscribe( + webinarId: string, + subscriberId: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(webinarId); + XValidators.validateNotEmpty(subscriberId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.Unsubscribe), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + { + key: XWebinarParam.SubscriberId, + value: subscriberId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region IsSubscribed ... + /** + * Check Specified User Subscribed on a Webinar or not ... + * + * @param webinarId + * @param subscriberId + * @param observe + * @param reportProgress + */ + public isSubscribed( + webinarId: string, + subscriberId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public isSubscribed( + webinarId: string, + subscriberId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public isSubscribed( + webinarId: string, + subscriberId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public isSubscribed( + webinarId: string, + subscriberId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(webinarId); + XValidators.validateNotEmpty(subscriberId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.IsSubscribed), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + { + key: XWebinarParam.SubscriberId, + value: subscriberId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetSubscriber ... + /** + * Retrieve Specified Subscriber ... + * + * @param webinarId + * @param subscriberId + * @param observe + * @param reportProgress + */ + public getSubscriber( + webinarId: string, + subscriberId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public getSubscriber( + webinarId: string, + subscriberId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public getSubscriber( + webinarId: string, + subscriberId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public getSubscriber( + webinarId: string, + subscriberId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(webinarId); + XValidators.validateNotEmpty(subscriberId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.GetSubscriber), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + { + key: XWebinarParam.SubscriberId, + value: subscriberId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetSubscribers ... + /** + * Retrieve Specified Webinars Subscribers ... + * + * @param webinarId + * @param observe + * @param reportProgress + */ + public getSubscribers( + webinarId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public getSubscribers( + webinarId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public getSubscribers( + webinarId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public getSubscribers( + webinarId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(webinarId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.GetSubscribers), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region QuerySubscribers ... + /** + * Query Specified Webinar's Subscribers ... + * + * @param query + * @param webinarId + * @param observe + * @param reportProgress + */ + public querySubscribers( + query: XQueryDto, + webinarId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public querySubscribers( + query: XQueryDto, + webinarId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public querySubscribers( + query: XQueryDto, + webinarId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public querySubscribers( + query: XQueryDto, + webinarId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(query); + XValidators.validateNotEmpty(webinarId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.QuerySubscribers), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get>( + endPointPath, + { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + } + ); + } + //#endregion + //#endregion + + // + //#region Files ... + // + //#region UploadFiles ... + /** + * Upload and Reference Files to Specified Webinar ... + * + * @param webinarId + * @param files + * @param connectionId + * @param observe + * @param reportProgress + */ + public uploadFiles( + webinarId: string, + files: XOneOrManyType, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public uploadFiles( + webinarId: string, + files: XOneOrManyType, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public uploadFiles( + webinarId: string, + files: XOneOrManyType, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public uploadFiles( + webinarId: string, + files: XOneOrManyType, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotNull(files); + XValidators.validateNotEmpty(webinarId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Preparing Form Data ... + let formData = new FormData(); + const filesArr = toArray(files); + if (hasChild(filesArr)) { + // + // Convert Files Array to Form Data ... + filesArr.forEach((f) => { + formData.append(XWebinarParam.Files, f, f.name); + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.UploadFiles), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: webinarId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.post>(endPointPath, formData, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region RemoveFiles ... + /** + * Remove Files of Specified Webinar ... + * + * @param id + * @param ids + * @param connectionId + * @param observe + * @param reportProgress + */ + public removeFiles( + id: string, + ids?: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public removeFiles( + id: string, + ids?: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public removeFiles( + id: string, + ids?: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public removeFiles( + id: string, + ids?: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Adding ids to Parmas ... + if (!isNullOrEmptyString(ids)) { + // + params = this.addCustomParam(params, { + key: XWebinarParam.Ids, + value: ids, + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.RemoveFiles), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetFiles ... + /** + * Get Files of Specified Webinar ... + * + * @param id + * @param connectionId + * @param observe + * @param reportProgress + */ + public getFiles( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public getFiles( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public getFiles( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public getFiles( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.GetFiles), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region StreamFiles ... + /** + * Stream Specified File of Specified Webinar ... + * + * @param id + * @param fileId + * @param observe + * @param reportProgress + */ + public streamFile( + id: string, + fileId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public streamFile( + id: string, + fileId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public streamFile( + id: string, + fileId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public streamFile( + id: string, + fileId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + XValidators.validateNotEmpty(fileId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.StreamFile), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + { + key: XWebinarParam.FileId, + value: fileId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + responseType: 'arraybuffer', + reportProgress, + }); + } + //#endregion + + // + //#region DownloadFile ... + /** + * Download Specified File of Specified Webinar ... + * + * @param id + * @param fileId + * @param observe + * @param reportProgress + */ + public downloadFile( + id: string, + fileId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public downloadFile( + id: string, + fileId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public downloadFile( + id: string, + fileId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public downloadFile( + id: string, + fileId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + XValidators.validateNotEmpty(fileId); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.DownloadFile), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + { + key: XWebinarParam.FileId, + value: fileId, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + responseType: 'blob', + reportProgress, + }); + } + //#endregion + //#endregion + + // + //#region Tags ... + // + //#region AttachTags ... + /** + * Attach Specified Tags of Specified Webinar ... + * + * @param id + * @param tags + * @param connectionId + * @param observe + * @param reportProgress + */ + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public attachTags( + id: string, + tags?: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tags to Params ... + if (!isNullOrEmptyString(tags)) { + // + params = this.addCustomParam(params, { + key: XWebinarParam.Tags, + value: tags, + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.AttachTags), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.post(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region DetachTags ... + /** + * Detach Specified Tags of Specified Webinar ... + * + * @param id + * @param tags + * @param connectionId + * @param observe + * @param reportProgress + */ + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public detachTags( + id: string, + tags?: string, + connectionId?: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Attach Tags to Params ... + if (!isNullOrEmptyString(tags)) { + // + params = this.addCustomParam(params, { + key: XWebinarParam.Tags, + value: tags, + }); + } + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + headers = applyConnectionIdToHeader(connectionId, headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.DetachTags), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.delete(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + + // + //#region GetTags ... + /** + * Retrieve Tags of Specified Webinar ... + * + * @param id + * @param observe + * @param reportProgress + */ + public getTags( + id: string, + observe?: 'body', + reportProgress?: boolean + ): Observable>; + public getTags( + id: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>>; + public getTags( + id: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>>; + public getTags( + id: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + // + // Validate Args ... + XValidators.validateNotEmpty(id); + + // + // Base Requirements ... + let params: HttpParams = null; + let headers: HttpHeaders = this.defaultHeaders; + + // + // Authentication ... + headers = this.addAuthentication(headers); + headers = this.addAcceptJson(headers); + headers = this.addContentType(headers); + + // + // Prepare Endpoint + const endPointPath = fillRouteParams( + // + // Base Route on Endpoint ... + this.getActionRoute(XWebinarServiceRoute.GetTags), + // + // Params ... + [ + { + key: XWebinarParam.Id, + value: id, + }, + ] + ); + + // + // Prepare Result ... + return this.httpClient.get>(endPointPath, { + withCredentials: this.apiConfig.withCredentials, + headers, + observe, + params, + reportProgress, + }); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.push.service.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.push.service.ts new file mode 100644 index 0000000..d9cbd4d --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinar.push.service.ts @@ -0,0 +1,260 @@ +import { Subject } from 'rxjs'; +import { + XRTCPeerService, + XHubConnectionDto, + XBaseWebRTCService, + IXPushServiceTokenFetcher, + XFrameworkPushServiceConfig, + X_FRAMEWORK_PUSH_SERVICE_CONFIG, + X_FRAMEWORK_PUSH_SERVICE_TOKEN_FETCHER, +} from 'x-framework-push-service'; +import { isNullOrEmptyString } from 'x-framework-core'; +import { XWebinarPushAction } from '../x-webinar.typings'; +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpTransportType, ITransport } from '@microsoft/signalr'; + +@Injectable({ + providedIn: 'root', +}) +export class XWebinarPushService extends XBaseWebRTCService { + // + //#region Props ... + onViewerJoined$ = new Subject<{ + viewerId: string; + webinarId: string; + userId: string; + username?: string; + }>(); + onViewerLeaved$ = new Subject<{ + viewerId: string; + webinarId: string; + userId: string; + username?: string; + }>(); + onWebinarOpened$ = new Subject(); + onWebinarClosed$ = new Subject(); + //#endregion + + // + //#region Constructor ... + constructor( + public rtcPeerService: XRTCPeerService, + @Inject(X_FRAMEWORK_PUSH_SERVICE_CONFIG) + public config: XFrameworkPushServiceConfig, + @Optional() + @Inject(X_FRAMEWORK_PUSH_SERVICE_TOKEN_FETCHER) + public tokenFetcher?: IXPushServiceTokenFetcher + ) { + super(config, tokenFetcher); + } + //#endregion + + // + //#region Abstracts ... + hubName(): string { + return 'webinarHub'; + } + + requiredAccessToken(): boolean { + return true; + } + + transportType(): HttpTransportType | ITransport { + return HttpTransportType.ServerSentEvents; + } + + skipNegotiation: false + + registerSubjects(): void { + super.registerSubjects(); + + // + this.onWebinarClosed((webinarId: string) => { + this.onWebinarClosed$.next(webinarId); + }); + + // + this.onWebinarClosed((webinarId: string) => { + this.onWebinarClosed$.next(webinarId); + }); + + // + this.onViewerJoined( + ( + viewerId: string, + webinarId: string, + userId: string, + username?: string + ) => { + // + this.onViewerJoined$.next({ + userId, + viewerId, + username, + webinarId, + }); + } + ); + + // + this.onViewerLeaved( + ( + viewerId: string, + webinarId: string, + userId: string, + username?: string + ) => { + // + this.onViewerLeaved$.next({ + userId, + viewerId, + username, + webinarId, + }); + } + ); + } + //#endregion + + // + //#region Actions ... + public async openWebinar(webinarId: string) { + // + // Validate ... + if (isNullOrEmptyString(webinarId)) { + return; + } + + // + await this.invoke(XWebinarPushAction.WebinarOpened, webinarId); + } + + public async closeWebinar(webinarId: string) { + // + // Validate ... + if (isNullOrEmptyString(webinarId)) { + return; + } + + // + await this.invoke(XWebinarPushAction.WebinarClosed, webinarId); + } + + public async joinWebinar(webinarId: string) { + // + // Validate ... + if (isNullOrEmptyString(webinarId)) { + return; + } + + // + await this.invoke(XWebinarPushAction.ViewerJoined, webinarId); + } + + public async leaveWebinar(webinarId: string) { + // + // Validate ... + if (isNullOrEmptyString(webinarId)) { + return; + } + + // + await this.invoke(XWebinarPushAction.ViewerLeaved, webinarId); + } + + public async webinarVisitors(webinarId: string) { + // + let result: Array = []; + + // + // Validate ... + if (isNullOrEmptyString(webinarId)) { + return result; + } + + // + result = await this.invoke>(XWebinarPushAction.WebinarVisitors, webinarId); + return result; + } + + public async sendMessage(webinarId: string, message: string) { + // + // Validate ... + if (isNullOrEmptyString(webinarId)) { + return; + } + + // + await this.invoke(XWebinarPushAction.Message, webinarId, message); + } + //#endregion + + // + //#region Event Handlers ... + // + //#region Onners ... + public onWebinarOpened(callback: (webinarId: string) => any) { + this.on(XWebinarPushAction.WebinarOpened, callback); + } + + public onWebinarClosed(callback: (webinarId?: string) => any) { + this.on(XWebinarPushAction.WebinarClosed, callback); + } + + public onViewerJoined( + callback: ( + connectionId: string, + webinarId: string, + userId: string, + username?: string + ) => any + ) { + this.on(XWebinarPushAction.ViewerJoined, callback); + } + + public onViewerLeaved( + callback: ( + connectionId: string, + webinarId: string, + userId: string, + username?: string + ) => any + ) { + this.on(XWebinarPushAction.ViewerLeaved, callback); + } + //#endregion + + // + //#region Offers ... + public offWebinarOpened(callback?: (webinarId: string) => any) { + this.off(XWebinarPushAction.WebinarOpened, callback); + } + + public offWebinarClosed(callback?: (webinarId?: string) => any) { + this.off(XWebinarPushAction.WebinarClosed, callback); + } + + public offViewerJoined( + callback?: ( + connectionId: string, + webinarId: string, + userId: string, + username?: string + ) => any + ) { + this.off(XWebinarPushAction.ViewerJoined, callback); + } + + public offViewerLeaved( + callback?: ( + connectionId: string, + webinarId: string, + userId: string, + username?: string + ) => any + ) { + this.off(XWebinarPushAction.ViewerLeaved, callback); + } + //#endregion + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinarsubscriber.entity.service.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinarsubscriber.entity.service.ts new file mode 100644 index 0000000..6021709 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/services/x-webinarsubscriber.entity.service.ts @@ -0,0 +1,39 @@ +import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { Inject, Injectable } from '@angular/core'; +import { XWebinarSubscriberDto } from '../models/x-webinar.dto'; +import { XApiEndPoint } from '../../typings/x-endpoint.typings'; +import { XBaseEntityService } from '../../base/x-base-entity.service'; +import { X_API_CONFIG, XApiConfiguration } from 'x-framework-identity-sdk'; +import { X_SAHERELM_API_SDK_CONFIG } from '../../tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from '../../config/x-saherelm-api-sdk.config'; + +/** + * Provides all Entity Actions as a Service ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XWebinarSubscriberEntityService extends XBaseEntityService< + XWebinarSubscriberDto, + number +> { + // + //#region Constructor ... + constructor( + protected router: Router, + protected httpClient: HttpClient, + @Inject(X_SAHERELM_API_SDK_CONFIG) config: XSaherElmApiSDKConfig, + @Inject(X_API_CONFIG) apiConfig: XApiConfiguration + ) { + super( + XApiEndPoint.WebinarsEntity, + true, + true, + httpClient, + config, + apiConfig + ); + } + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/x-webinar.services.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/x-webinar.services.ts new file mode 100644 index 0000000..4c28731 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/x-webinar.services.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@angular/core'; +import { XWebinarPushService } from './services/x-webinar.push.service'; +import { XWebinarEntityService } from './services/x-webinar.entity.service'; +import { XWebinarProviderService } from './services/x-webinar.provider.service'; +import { XWebinarEntityPushService } from './services/x-webinar.entity.push.service'; +import { XWebinarSubscriberEntityService } from './services/x-webinarsubscriber.entity.service'; + +/** + * Export All Provided Webinar related Services ... + */ +@Injectable({ + providedIn: 'root', +}) +export class XWebinarServices { + // + //#region Constructor ... + public constructor( + public webinarPushService: XWebinarPushService, + public webinarEntityService: XWebinarEntityService, + public webinarProviderService: XWebinarProviderService, + public webinarEntityPushService: XWebinarEntityPushService, + public webinarSubscriberEntityService: XWebinarSubscriberEntityService + ) {} + //#endregion +} diff --git a/projects/x-saherelm-api-sdk/src/lib/webinars/x-webinar.typings.ts b/projects/x-saherelm-api-sdk/src/lib/webinars/x-webinar.typings.ts new file mode 100644 index 0000000..2cdb50e --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/webinars/x-webinar.typings.ts @@ -0,0 +1,82 @@ +/** + * All Available EndPoint Routes ... + */ +export enum XWebinarServiceRoute { + CreateWebinar = '', + GetWebinar = '{id}', + GetWebinars = 'All', + UpdateWebinar = '{id}', + RemoveWebinar = '{id}', + QueryWebinars = 'Query', + GetFiles = '{id}/Files', + GetTags = '{id}/Tags', + AttachTags = '{id}/Tags', + DetachTags = '{id}/Tags', + RemoveFiles = '{id}/Files', + UploadFiles = '{id}/Files', + QueryOwnedWebinars = 'Query/Owned', + GetSubscribers = '{id}/Subscribers', + QueryJoinableWebinars = 'Query/Joinable', + StreamFile = '{id}/Files/{fileId}/Stream', + Subscribe = '{id}/Subscribe/{subscriberId}', + QuerySubscribers = '{id}/Subscribers/Query', + DownloadFile = '{id}/Files/{fileId}/Download', + Unsubscribe = '{id}/Unsubscribe/{subscriberId}', + GetSubscriber = '{id}/Subscriber/{subscriberId}', + IsSubscribed = '{id}/IsSubscribed/{subscriberId}', +} + +/** + * All Params Which Used in Related Services ... + */ +export enum XWebinarParam { + Id = 'id', + Ids = 'ids', + Tags = 'tags', + Files = 'files', + FileId = 'fileId', + SubscriberId = 'subscriberId', +} + +/** + * Webinar Hub Actions ... + */ +export enum XWebinarPushAction { + /// + /// When a Webinar is Available to Join ... + /// + WebinarOpened = 'WebinarOpened', + + /// + /// When a Webinar Closed ... + /// + WebinarClosed = 'WebinarClosed', + + /// + /// When a Viewer is Joined to Webinar ... + /// + ViewerJoined = 'ViewerJoined', + + /// + /// When a Webinar Subscriber Leaved a Webinar ... + /// + ViewerLeaved = 'ViewerLeaved', + + /// + /// Retrieve Specified Webinar Visitors ... + /// + WebinarVisitors = 'WebinarVisitors', + + /// + /// Send a Message to Webinar ... + /// + Message = 'Message', +} + +/** + * Webinar Entity Hub Actions ... + */ +export enum XWebinarEntityPushAction { + Subscribe = 'Subscribe', + Unsubscribe = 'Unsubscribe', +} diff --git a/projects/x-saherelm-api-sdk/src/lib/x-saherelm-api-sdk.module.ts b/projects/x-saherelm-api-sdk/src/lib/x-saherelm-api-sdk.module.ts new file mode 100644 index 0000000..b188527 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/x-saherelm-api-sdk.module.ts @@ -0,0 +1,26 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HttpClientModule } from '@angular/common/http'; +import { XFrameworkCoreModule } from 'x-framework-core'; +import { XFrameworkServicesModule } from 'x-framework-services'; +import { XFrameworkIdentitySdkModule } from 'x-framework-identity-sdk'; + +@NgModule({ + declarations: [], + imports: [ + CommonModule, + HttpClientModule, + XFrameworkCoreModule, + XFrameworkServicesModule, + XFrameworkIdentitySdkModule, + ], + exports: [ + CommonModule, + HttpClientModule, + XFrameworkCoreModule, + XFrameworkServicesModule, + XFrameworkIdentitySdkModule, + ], + providers: [], +}) +export class XSaherElmApiSdkModule {} diff --git a/projects/x-saherelm-api-sdk/src/lib/x-saherelm-api.service.ts b/projects/x-saherelm-api-sdk/src/lib/x-saherelm-api.service.ts new file mode 100644 index 0000000..ebc5d58 --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/lib/x-saherelm-api.service.ts @@ -0,0 +1,30 @@ +import { XLoggable } from 'x-framework-core'; +import { Inject, Injectable } from '@angular/core'; +import { XTagServices } from './tags/x-tag.services'; +import { XFileServices } from './files/x-file.services'; +import { XTermsServices } from './terms/x-terms.service'; +import { XStringServices } from './strings/x-string.services'; +import { XWebinarServices } from './webinars/x-webinar.services'; +import { X_SAHERELM_API_SDK_CONFIG } from './tokens/x-injectable-tokens'; +import { XSaherElmApiSDKConfig } from './config/x-saherelm-api-sdk.config'; +import { XConfigurationsService } from './configurations/x-configurations.service'; + +@Injectable({ + providedIn: 'root', +}) +export class XSaherElmAPIService extends XLoggable { + // + //#region Constructor ... + constructor( + public tags: XTagServices, + public files: XFileServices, + public terms: XTermsServices, + public strings: XStringServices, + public webinars: XWebinarServices, + @Inject(X_SAHERELM_API_SDK_CONFIG) + public config: XSaherElmApiSDKConfig, + public configurationService: XConfigurationsService + ) { + super(config); + } +} diff --git a/projects/x-saherelm-api-sdk/src/public-api.ts b/projects/x-saherelm-api-sdk/src/public-api.ts new file mode 100644 index 0000000..7a913fc --- /dev/null +++ b/projects/x-saherelm-api-sdk/src/public-api.ts @@ -0,0 +1,99 @@ +/* + * Public API Surface of x-framework-api-sdk + */ +// +// Base ... +export * from './lib/base/x-base.guard'; +export * from './lib/base/x-base-entity.service'; +export * from './lib/base/i-x-entity-actions.interface'; + +// +// Config ... +export * from './lib/config/x-saherelm-api-sdk.config'; + +// +// Models ... +export * from './lib/models/x-person.dto'; +export * from './lib/models/x-reference.dto'; + +// +// Tokens ... +export * from './lib/tokens/x-injectable-tokens'; + +// +// Tools ... +export * from './lib/tools/x-role.tools'; +export * from './lib/tools/x-model.tools'; +export * from './lib/tools/x-route.tools'; + +// +// Services ... +export * from './lib/services/x-push-token-fetcher.service'; + +// +// Typings ... +export * from './lib/typings/x-role.typings'; +export * from './lib/strings/x-string.typings'; +export * from './lib/typings/x-endpoint.typings'; +export * from './lib/typings/x-push-provider.typings'; + +// +// Guards ... +export * from './lib/guards/user.guard'; +export * from './lib/guards/admin.guard'; +export * from './lib/guards/agent.guard'; +export * from './lib/guards/admin-or-agent.guard'; + +// +// Strings ... +export * from './lib/strings/x-string.typings'; +export * from './lib/strings/x-string.services'; +export * from './lib/strings/models/x-string.dto'; +export * from './lib/configurations/x-configurations.service'; +export * from './lib/strings/services/x-string.entity.service'; +export * from './lib/strings/services/x-string.provider.service'; +export * from './lib/strings/services/x-string.entity.push.service'; + +// +// Terms ... +export * from './lib/terms/x-terms.service'; +export * from './lib/terms/x-terms.typings.dto'; +export * from './lib/terms/services/x-terms.push.service'; +export * from './lib/terms/services/x-terms.provider.service'; + +// +// Tags ... +export * from './lib/tags/x-tag.typings'; +export * from './lib/tags/x-tag.services'; +export * from './lib/tags/models/x-tag.dto'; +export * from './lib/tags/services/x-tag.entity.service'; +export * from './lib/tags/services/x-tag.provider.service'; +export * from './lib/tags/services/x-tag.entity.push.service'; + +// +// Files ... +export * from './lib/files/x-file.typings'; +export * from './lib/files/x-file.services'; +export * from './lib/files/models/x-file.dto'; +export * from './lib/files/services/x-file.entity.service'; +export * from './lib/files/services/x-file.provider.service'; +export * from './lib/files/services/x-file.entity.push.service'; + +// +// Webinars ... +export * from './lib/webinars/x-webinar.typings'; +export * from './lib/webinars/x-webinar.services'; +export * from './lib/webinars/models/x-webinar.dto'; +export * from './lib/webinars/services/x-webinar.push.service'; +export * from './lib/webinars/services/x-webinar.entity.service'; +export * from './lib/webinars/services/x-webinar.provider.service'; +export * from './lib/webinars/services/x-webinar.entity.push.service'; +export * from './lib/webinars/services/x-webinarsubscriber.entity.service'; + +// +// Module Service ... +export * from './lib/x-saherelm-api.service'; + +// +// Module ... +export * from './lib/x-saherelm-api-sdk.module'; diff --git a/projects/x-saherelm-api-sdk/tsconfig.lib.ivy.json b/projects/x-saherelm-api-sdk/tsconfig.lib.ivy.json new file mode 100644 index 0000000..20d3490 --- /dev/null +++ b/projects/x-saherelm-api-sdk/tsconfig.lib.ivy.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.lib.json", + "angularCompilerOptions": { + "enableIvy": true + } + } + \ No newline at end of file diff --git a/projects/x-saherelm-api-sdk/tsconfig.lib.json b/projects/x-saherelm-api-sdk/tsconfig.lib.json new file mode 100644 index 0000000..1407202 --- /dev/null +++ b/projects/x-saherelm-api-sdk/tsconfig.lib.json @@ -0,0 +1,20 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/lib", + "target": "es2015", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "types": [], + "lib": [ + "dom", + "es2018" + ] + }, + "exclude": [ + "src/test.ts", + "**/*.spec.ts" + ] +} diff --git a/projects/x-saherelm-api-sdk/tsconfig.lib.prod.json b/projects/x-saherelm-api-sdk/tsconfig.lib.prod.json new file mode 100644 index 0000000..06de549 --- /dev/null +++ b/projects/x-saherelm-api-sdk/tsconfig.lib.prod.json @@ -0,0 +1,10 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.lib.json", + "compilerOptions": { + "declarationMap": false + }, + "angularCompilerOptions": { + "compilationMode": "partial" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6f90b42 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,39 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "compileOnSave": false, + "compilerOptions": { + "strict": true, + "baseUrl": "./", + "sourceMap": true, + "target": "es2017", + "module": "es2020", + "declaration": false, + "skipLibCheck": true, + "noImplicitAny": true, + "importHelpers": true, + "strictNullChecks": false, + "noImplicitReturns": true, + "moduleResolution": "node", + "downlevelIteration": true, + "outDir": "./dist/out-tsc", + "experimentalDecorators": true, + "noFallthroughCasesInSwitch": true, + "forceConsistentCasingInFileNames": true, + "lib": [ + "es2018", + "dom" + ], + "paths": { + "x-saherelm-api-sdk": [ + "dist/x-saherelm-api-sdk/x-saherelm-api-sdk", + "dist/x-saherelm-api-sdk" + ] + } + }, + "angularCompilerOptions": { + "strictTemplates": true, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "enableI18nLegacyMessageIdFormat": false + } +}