diff --git a/package.json b/package.json index 151b6856..f758c16f 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,11 @@ "version": "1.0.0", "description": "tezosLink project", "_moduleAliases": { - "@Site": "./dist/site", - "@Api": "./dist/site/api", + "@App": "./dist/app", + "@Api": "./dist/app/api", "@Pages": "./dist/pages", "@Common": "./dist/common", - "@Services": "./dist/common/services", + "@Services": "./dist/services", "@Repositories": "./dist/common/repositories", "@Entries": "./dist/common/entries", "@Config": "./dist/common/config", @@ -17,7 +17,7 @@ }, "scripts": { "build": "tsc", - "api:start": "node ./dist/entries/Site.js", + "api:start": "node ./dist/entries/App.js", "dev": "nodemon -V", "api:dev": "nodemon -V --exec 'tsc && npm run api:start'", "build:test": "tsc && mocha ./dist/entries/Test.js", diff --git a/src/app/api/ProjectController.ts b/src/app/api/ProjectController.ts index b865b2b1..84735562 100644 --- a/src/app/api/ProjectController.ts +++ b/src/app/api/ProjectController.ts @@ -2,7 +2,7 @@ import { type Response, type Request } from "express"; import { Controller, Get } from "@ControllerPattern/index"; import { Service } from "typedi"; import { IsNotEmpty, IsString, IsUUID, validateOrReject } from "class-validator"; -import ProjectService from "@Services/_TemplateService/_TemplateService"; +// import ProjectService from "@Services/_TemplateService/_TemplateService"; import ApiController from "@Common/system/controller-pattern/ApiController"; class Params { @@ -15,7 +15,7 @@ class Params { @Controller() @Service() export default class ProjectController extends ApiController { - constructor(private projectService: ProjectService) { + constructor() { super(); } @@ -38,12 +38,12 @@ export default class ProjectController extends ApiController { return; } - const project = await this.projectService.getByUUID(); + // const project = await this.projectService.getByUUID(); // if (!project) { // this.httpNotFoundRequest(res); // return; // } - this.httpSuccess(res, project); + // this.httpSuccess(res, project); } } diff --git a/src/app/api/UserController.ts b/src/app/api/UserController.ts new file mode 100644 index 00000000..966aebdc --- /dev/null +++ b/src/app/api/UserController.ts @@ -0,0 +1,38 @@ +import { type Response, type Request } from "express"; +import { Controller, Get } from "@ControllerPattern/index"; +// import { IsNotEmpty, IsString, IsUUID } from "class-validator"; +import { Service } from "typedi"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import UsersService from "@Services/UsersService/UsersService"; + +// class Params { +// @IsString() +// @IsNotEmpty() +// @IsUUID() +// public uuid!: string; +// } + +@Controller() +@Service() +export default class UserController extends ApiController { + tokensService: any; + constructor(private userService: UsersService) { + super(); + } + + @Get("/api/users") + protected async get(req: Request, response: Response) { + console.log("UserController > get > response"); + // request: Request + // const query = this.buildQueryAsObject>(request); + try { + // await validateOrReject(QueryService.createFrom>(query), { + // forbidUnknownValues: true, + // }); + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.userService.getByUid("uid")); + } +} diff --git a/src/app/index.ts b/src/app/index.ts index 84bb36c2..d57f2247 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -1,11 +1,13 @@ import { Container } from "typedi"; import HomeController from "./HomeController"; import ProjectController from "./api/ProjectController"; +import UserController from "./api/UserController"; export default { start: () => { Container.get(HomeController); Container.get(ProjectController); + Container.get(UserController); } } diff --git a/src/common/config/variables/Variables.ts b/src/common/config/variables/Variables.ts index 66d13ad0..482a9dce 100644 --- a/src/common/config/variables/Variables.ts +++ b/src/common/config/variables/Variables.ts @@ -19,23 +19,17 @@ export class BackendVariables { @IsNotEmpty() public readonly DATABASE_NAME!: string; - @IsOptional() - public readonly API_LABEL!: string; - - @IsNotEmpty() - public readonly API_PORT!: string; - @IsNotEmpty() public readonly API_ROOT_URL!: string; @IsOptional() - public readonly SITE_LABEL!: string; + public readonly APP_LABEL!: string; @IsNotEmpty() - public readonly SITE_PORT!: string; + public readonly APP_PORT!: string; @IsNotEmpty() - public readonly SITE_ROOT_URL!: string; + public readonly APP_ROOT_URL!: string; public readonly NODE_ENV = process.env.NODE_ENV; @@ -46,11 +40,10 @@ export class BackendVariables { this.DATABASE_USER = process.env["DATABASE_USER"]!; this.DATABASE_PASSWORD = process.env["DATABASE_PASSWORD"]!; this.DATABASE_NAME = process.env["DATABASE_NAME"]!; - this.API_PORT = process.env["API_PORT"]!; this.API_ROOT_URL = process.env["API_ROOT_URL"]!; - this.SITE_PORT = process.env["SITE_PORT"]!; - this.SITE_ROOT_URL = process.env["SITE_ROOT_URL"]!; - this.SITE_LABEL = process.env["SITE_LABEL"]!; + this.APP_PORT = process.env["APP_PORT"]!; + this.APP_ROOT_URL = process.env["APP_ROOT_URL"]!; + this.APP_LABEL = process.env["APP_LABEL"]!; } public async validate() { await validateOrReject(this); diff --git a/src/common/services/_TemplateService/_TemplateService.ts b/src/common/services/_TemplateService/_TemplateService.ts deleted file mode 100644 index 33020448..00000000 --- a/src/common/services/_TemplateService/_TemplateService.ts +++ /dev/null @@ -1,41 +0,0 @@ -// import ProjectsRepository from "@Common/repositories/projects/ProjectsRepository"; -import BaseService from "@Services/BaseService"; -import { Service } from "typedi"; - -@Service() -export default class ProjectsService extends BaseService { - constructor() { - super(); - } - - /** - * @throws {Error} If projects are undefined - * @returns : Promise - * @param : query: ReturnType - */ - public async getByCriterias() { - // return this.projectRepository.findMany(query); - } - - /** - * @throws {Error} If project is undefined - * @returns : Partial - * @param : t : T - */ - public async getByUUID() { - // const project = await this.projectRepository.findOne(projectEntity); - // if (!project) Promise.reject(new Error("Cannot get project by uuid")); - // return project; - } - /** - * - * @throws {Error} If project cannot be created - * @returns : T - * @param : projectEntity: Partial - */ - public async create() { - // const project = await this.projectRepository.create(projectEntity); - // if (!project) Promise.reject(new Error("Cannot create project")); - // return project; - } -} diff --git a/src/entries/Site.ts b/src/entries/App.ts similarity index 76% rename from src/entries/Site.ts rename to src/entries/App.ts index 49c08318..5db0695d 100644 --- a/src/entries/Site.ts +++ b/src/entries/App.ts @@ -2,20 +2,20 @@ import "module-alias/register"; import "reflect-metadata"; import { Container } from "typedi"; import ExpressServer from "@Common/system/ExpressServer"; -import routes from "@Site/index"; +import routes from "@App/index"; import cors from "cors"; import bodyParser from "body-parser"; // import TezosLink from "@Common/databases/TezosLink"; -import errorHandler from "@Site/middlewares/ErrorHandler"; +import errorHandler from "@App/middlewares/ErrorHandler"; import { BackendVariables } from "@Common/config/variables/Variables"; (async () => { try { const variables = await Container.get(BackendVariables).validate(); - const port = variables.SITE_PORT; - const rootUrl = variables.SITE_ROOT_URL; - const label = variables.SITE_LABEL ?? "Unknown Service"; + const port = variables.APP_PORT; + const rootUrl = variables.APP_ROOT_URL; + const label = variables.APP_LABEL ?? "Unknown Service"; // Container.get(TezosLink).connect(); Container.get(ExpressServer).init({ diff --git a/src/common/services/BaseService.ts b/src/services/BaseService.ts similarity index 100% rename from src/common/services/BaseService.ts rename to src/services/BaseService.ts diff --git a/src/services/UsersService/UsersService.ts b/src/services/UsersService/UsersService.ts new file mode 100644 index 00000000..7261b9b6 --- /dev/null +++ b/src/services/UsersService/UsersService.ts @@ -0,0 +1,32 @@ +// import ProjectsRepository from "@Common/repositories/projects/ProjectsRepository"; +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; + +@Service() +export default class UsersService extends BaseService { + constructor() { + super(); + } + + /** + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async getByUid(uuid: string) { + // const user = await this.usersRepository.findOne(uuid); + // if (!user) Promise.reject(new Error("Cannot get user by uuid")); + return "User/getByUid > Not implemented yet"; + } + + /** + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async create() { + // const project = await this.projectRepository.create(projectEntity); + // if (!project) Promise.reject(new Error("Cannot create project")); + // return project; + } +} diff --git a/tsconfig.json b/tsconfig.json index e22f3657..06ff79ce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -38,14 +38,14 @@ "moduleResolution": "node", "baseUrl": ".", "paths": { - "@Site/*": [ + "@App/*": [ "src/app/*" ], "@Api/*": [ "src/app/api/*" ], "@Services/*": [ - "src/common/services/*" + "src/services/*" ], "@Repositories/*": [ "src/common/repositories/*" @@ -90,7 +90,8 @@ }, "include": [ "**/*.ts", - "**/*.tsx" + "**/*.tsx", + "src/app/api/UserController.ts" ], "exclude": [ "node_modules"