✨ created our first service and controller for users > api/users
This commit is contained in:
parent
fafd81db04
commit
f95978037a
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
38
src/app/api/UserController.ts
Normal file
38
src/app/api/UserController.ts
Normal file
@ -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<Partial<TokenSupportEntity>>(request);
|
||||
try {
|
||||
// await validateOrReject(QueryService.createFrom<Partial<TokenSupportEntity>>(query), {
|
||||
// forbidUnknownValues: true,
|
||||
// });
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
this.httpSuccess(response, await this.userService.getByUid("uid"));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<T[]>
|
||||
* @param : query: ReturnType<typeof processFindManyQuery>
|
||||
*/
|
||||
public async getByCriterias() {
|
||||
// return this.projectRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws {Error} If project is undefined
|
||||
* @returns : Partial<T>
|
||||
* @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<ProjectEntity>
|
||||
*/
|
||||
public async create() {
|
||||
// const project = await this.projectRepository.create(projectEntity);
|
||||
// if (!project) Promise.reject(new Error("Cannot create project"));
|
||||
// return project;
|
||||
}
|
||||
}
|
@ -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({
|
32
src/services/UsersService/UsersService.ts
Normal file
32
src/services/UsersService/UsersService.ts
Normal file
@ -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<ProjectEntity>
|
||||
*/
|
||||
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<ProjectEntity>
|
||||
*/
|
||||
public async create() {
|
||||
// const project = await this.projectRepository.create(projectEntity);
|
||||
// if (!project) Promise.reject(new Error("Cannot create project"));
|
||||
// return project;
|
||||
}
|
||||
}
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user