UNPKG

@ducvnv/mirai-cms-role

Version:

<p align="center"> <a href="https://mirailabs.co/" target="blank"><img src="https://mirailabs.co/_next/static/media/logo.2a6685c4.svg" width="120" alt="Nest Logo" /></a> </p>

108 lines (107 loc) 5.69 kB
"use strict"; // import {forwardRef, Inject, Injectable, OnModuleInit, VersioningOptions} from "@nestjs/common"; // import {ApplicationConfig, DiscoveryService, MetadataScanner, Reflector} from "@nestjs/core"; // import {bodyRequestHubSync} from "../model/requests/body.hub.request.sync"; // // @Injectable() // export class RouterHubService implements OnModuleInit { // constructor( // @Inject(forwardRef(() => DiscoveryService)) // private readonly discoveryService: DiscoveryService, // @Inject(Reflector.name) // private readonly reflector: Reflector, // @Inject(forwardRef(() => ApplicationConfig)) // private readonly applicationConfig: ApplicationConfig, // private readonly metadataScanner: MetadataScanner, // ) { // } // // async onModuleInit() { // let routers :bodyRequestHubSync[] = [] // const globalPrefix = this.applicationConfig.getGlobalPrefix().replace(/^\/|\/$/g, ''); // const defaultVersion: VersioningOptions | undefined = this.applicationConfig.getVersioning(); // const controllers = this.discoveryService.getControllers(); // controllers.forEach((controller) => { // const { instance } = controller; // const prototype = Object.getPrototypeOf(instance); // // this.metadataScanner.scanFromPrototype(instance, prototype, (methodName) => { // const method = prototype[methodName]; // const apiOperationMetadata = this.reflector.get('swagger/apiOperation', method); // const paths = this.reflector.get<string>('path', method); // const methodType = this.reflector.get<RequestMethod[]>('method', method); // const controllerVersion = this.reflector.get<string>(VERSION_METADATA, prototype.constructor); // const controllerPath = this.reflector.get<string>(PATH_METADATA, prototype.constructor); // const version = `${(this.generateVersion(defaultVersion,controllerVersion)||'')}`; // const pathController = controllerPath === '/' ? '' : `/${controllerPath.replace(/^\/|\/$/g, '')}`; // const path = paths === '/' ? '' : `/${paths.replace(/^\/|\/$/g, '')}`; // const prefix = globalPrefix === undefined ? '' : `${globalPrefix.replace(/^\/|\/$/g, '')}`; // const pathMap = `${prefix}${version}${pathController}${path}`.replace(/^\/|\/$/g, ''); // switch (Number(methodType)) { // case 1: // routers.push({ // method: methodsEnums.POST.toString(), // path: pathMap, // function: methodName, // description: apiOperationMetadata === undefined ? '' : apiOperationMetadata['description'], // }); // break; // case 2: // routers.push({ // method: methodsEnums.PUT.toString(), // path: pathMap, // function: methodName, // description: apiOperationMetadata === undefined ? '' : apiOperationMetadata['description'], // }); // break; // case 3: // routers.push({ // method: methodsEnums.DELETE.toString(), // path: pathMap, // function: methodName, // description: apiOperationMetadata === undefined ? '' : apiOperationMetadata['description'], // }); // break; // case 4: // routers.push({ // method: methodsEnums.PATCH.toString(), // path: pathMap, // function: methodName, // description: apiOperationMetadata === undefined ? '' : apiOperationMetadata['description'], // }); // break; // case 0: // routers.push({ // method: methodsEnums.GET.toString(), // path: pathMap, // function: methodName, // description: apiOperationMetadata === undefined ? '' : apiOperationMetadata['description'], // }); // break; // } // }); // }); // await this.syncRouter(routers); // } // // private async syncRouter(info: bodyRequestSync[]): Promise<boolean> { // try{ // const result = await API.postApi(env.SYNC_URL, info, '', env.KEY_SERVICE) as ResponseModel; // return result.data; // }catch (e){ // console.log(`[Error] sync log : ${e}`); // return false; // } // // } // // private generateVersion(defaultVersion: any, versionController: any): string| undefined { // if (!versionController && !defaultVersion) { // return ''; // } else if ((versionController && !defaultVersion) || (versionController && defaultVersion)) { // return `/v${versionController?.toString()}`.toString(); // } else if (!versionController && defaultVersion) { // return `/v${defaultVersion['defaultVersion']?.toString()}`.toString(); // } // } // }