diff --git a/src/app/api/CustomersController.ts b/src/app/api/CustomersController.ts new file mode 100644 index 00000000..ba3c2951 --- /dev/null +++ b/src/app/api/CustomersController.ts @@ -0,0 +1,82 @@ +import { type Response, type Request } from "express"; +import { Controller, Get, Post, Put } from "@ControllerPattern/index"; +import { Service } from "typedi"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import CustomersService from "@Services/CustomersService/CustomersService"; +// import { IsNotEmpty, IsString, IsUUID } from "class-validator"; + +// class Params { +// @IsString() +// @IsNotEmpty() +// @IsUUID() +// public uuid!: string; +// } + +@Controller() +@Service() +export default class CustomersController extends ApiController { + tokensService: any; + constructor(private customersService: CustomersService) { + super(); + } + + /** + * @description Get all customers + * @returns ICustomer[] list of customers + */ + @Get("/api/customers") + protected async get(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.customersService.get()); + } + + /** + * @description Create a new customer + * @returns ICustomer created + */ + @Post("/api/customers") + protected async post(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.customersService.create()); + } + + /** + * @description Modify a specific customer by uid + * @returns ICustomer modified + */ + @Put("/api/customers/:uid") + protected async put(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.customersService.put()); + } + + /** + * @description Get a specific customer by uid + * @returns ICustomer + */ + @Get("/api/customers/:uid") + protected async getOneByUid(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.customersService.getByUid("uid")); + } +} diff --git a/src/app/api/DeedsController.ts b/src/app/api/DeedsController.ts new file mode 100644 index 00000000..33eff9e1 --- /dev/null +++ b/src/app/api/DeedsController.ts @@ -0,0 +1,82 @@ +import { type Response, type Request } from "express"; +import { Controller, Get, Post, Put } from "@ControllerPattern/index"; +import { Service } from "typedi"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import DeedsService from "@Services/DeedsService/DeedsService"; +// import { IsNotEmpty, IsString, IsUUID } from "class-validator"; + +// class Params { +// @IsString() +// @IsNotEmpty() +// @IsUUID() +// public uuid!: string; +// } + +@Controller() +@Service() +export default class DeedsController extends ApiController { + tokensService: any; + constructor(private deedsService: DeedsService) { + super(); + } + + /** + * @description Get all deeds + * @returns IDeed[] list of deeds + */ + @Get("/api/deeds") + protected async get(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.deedsService.get()); + } + + /** + * @description Create a new deed + * @returns IDeed created + */ + @Post("/api/deeds") + protected async post(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.deedsService.create()); + } + + /** + * @description Modify a specific deed by uid + * @returns IDeed modified + */ + @Put("/api/deeds/:uid") + protected async put(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.deedsService.put()); + } + + /** + * @description Get a specific deed by uid + * @returns IDeed + */ + @Get("/api/deeds/:uid") + protected async getOneByUid(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.deedsService.getByUid("uid")); + } +} diff --git a/src/app/api/FoldersController.ts b/src/app/api/FoldersController.ts new file mode 100644 index 00000000..5d3ad9ef --- /dev/null +++ b/src/app/api/FoldersController.ts @@ -0,0 +1,82 @@ +import { type Response, type Request } from "express"; +import { Controller, Get, Post, Put } from "@ControllerPattern/index"; +import { Service } from "typedi"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import FoldersService from "@Services/FoldersService/FoldersService"; +// import { IsNotEmpty, IsString, IsUUID } from "class-validator"; + +// class Params { +// @IsString() +// @IsNotEmpty() +// @IsUUID() +// public uuid!: string; +// } + +@Controller() +@Service() +export default class FolderController extends ApiController { + tokensService: any; + constructor(private foldersService: FoldersService) { + super(); + } + + /** + * @description Get all folders + * @returns IFolder[] list of folders + */ + @Get("/api/folders") + protected async get(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.foldersService.get()); + } + + /** + * @description Create a new folder + * @returns IFolder created + */ + @Post("/api/folders") + protected async post(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.foldersService.create()); + } + + /** + * @description Modify a specific folder by uid + * @returns IFolder modified + */ + @Put("/api/folders/:uid") + protected async put(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.foldersService.put()); + } + + /** + * @description Get a specific folder by uid + * @returns IFolder + */ + @Get("/api/folders/:uid") + protected async getOneByUid(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.foldersService.getByUid("uid")); + } +} diff --git a/src/app/api/OfficesController.ts b/src/app/api/OfficesController.ts new file mode 100644 index 00000000..b7de36d5 --- /dev/null +++ b/src/app/api/OfficesController.ts @@ -0,0 +1,82 @@ +import { type Response, type Request } from "express"; +import { Controller, Get, Post, Put } from "@ControllerPattern/index"; +import { Service } from "typedi"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import OfficesService from "@Services/OfficesService/OfficesService"; +// import { IsNotEmpty, IsString, IsUUID } from "class-validator"; + +// class Params { +// @IsString() +// @IsNotEmpty() +// @IsUUID() +// public uuid!: string; +// } + +@Controller() +@Service() +export default class OfficesController extends ApiController { + tokensService: any; + constructor(private officesService: OfficesService) { + super(); + } + + /** + * @description Get all offices + * @returns IOffice[] list of offices + */ + @Get("/api/offices") + protected async get(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.officesService.get()); + } + + /** + * @description Create a new office + * @returns IOffice created + */ + @Post("/api/offices") + protected async post(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.officesService.create()); + } + + /** + * @description Modify a specific office by uid + * @returns IOffice modified + */ + @Put("/api/offices/:uid") + protected async put(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.officesService.put()); + } + + /** + * @description Get a specific office by uid + * @returns IOffice + */ + @Get("/api/offices/:uid") + protected async getOneByUid(req: Request, response: Response) { + try { + // TODO + } catch (error) { + this.httpBadRequest(response, error); + return; + } + this.httpSuccess(response, await this.officesService.getByUid("uid")); + } +} diff --git a/src/app/api/ProjectController.ts b/src/app/api/ProjectController.ts deleted file mode 100644 index 84735562..00000000 --- a/src/app/api/ProjectController.ts +++ /dev/null @@ -1,49 +0,0 @@ -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 ApiController from "@Common/system/controller-pattern/ApiController"; - -class Params { - @IsString() - @IsNotEmpty() - @IsUUID() - public uuid!: string; -} - -@Controller() -@Service() -export default class ProjectController extends ApiController { - constructor() { - super(); - } - - @Get("/api/projects") - protected async get(req: Request, res: Response) { - - // const query = processFindManyQuery(req.query); - this.httpSuccess(res, { message: "get" }); - } - - @Get("/api/projects/:uuid") - protected async getByUUID(req: Request, res: Response) { - const { uuid } = req.params as Partial; - const params = new Params(); - params.uuid = uuid!; - try { - await validateOrReject(params, { forbidUnknownValues: true }); - } catch (error) { - this.httpBadRequest(res, error); - return; - } - - // const project = await this.projectService.getByUUID(); - // if (!project) { - // this.httpNotFoundRequest(res); - // return; - // } - // this.httpSuccess(res, project); - } -} - diff --git a/src/app/api/UserController.ts b/src/app/api/UsersController.ts similarity index 80% rename from src/app/api/UserController.ts rename to src/app/api/UsersController.ts index 982eecab..3491fec7 100644 --- a/src/app/api/UserController.ts +++ b/src/app/api/UsersController.ts @@ -14,9 +14,9 @@ import UsersService from "@Services/UsersService/UsersService"; @Controller() @Service() -export default class UserController extends ApiController { +export default class UsersController extends ApiController { tokensService: any; - constructor(private userService: UsersService) { + constructor(private usersService: UsersService) { super(); } @@ -32,7 +32,7 @@ export default class UserController extends ApiController { this.httpBadRequest(response, error); return; } - this.httpSuccess(response, await this.userService.get()); + this.httpSuccess(response, await this.usersService.get()); } /** @@ -47,7 +47,7 @@ export default class UserController extends ApiController { this.httpBadRequest(response, error); return; } - this.httpSuccess(response, await this.userService.create()); + this.httpSuccess(response, await this.usersService.create()); } /** @@ -62,7 +62,7 @@ export default class UserController extends ApiController { this.httpBadRequest(response, error); return; } - this.httpSuccess(response, await this.userService.create()); + this.httpSuccess(response, await this.usersService.put()); } /** @@ -77,6 +77,6 @@ export default class UserController extends ApiController { this.httpBadRequest(response, error); return; } - this.httpSuccess(response, await this.userService.getByUid("uid")); + this.httpSuccess(response, await this.usersService.getByUid("uid")); } } diff --git a/src/app/api/project/UserController.ts b/src/app/api/projects/UserController.ts similarity index 100% rename from src/app/api/project/UserController.ts rename to src/app/api/projects/UserController.ts diff --git a/src/app/index.ts b/src/app/index.ts index d57f2247..f9608c24 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -1,13 +1,21 @@ import { Container } from "typedi"; import HomeController from "./HomeController"; -import ProjectController from "./api/ProjectController"; -import UserController from "./api/UserController"; - +import UsersController from "./api/UsersController"; +import FoldersController from "./api/FoldersController"; +import CustomersController from "./api/CustomersController"; +import OfficesController from "./api/OfficesController"; +import DeedsController from "./api/DeedsController"; +/** + * @description This allow to declare all controllers used in the application + */ export default { - start: () => { - Container.get(HomeController); - Container.get(ProjectController); - Container.get(UserController); - } -} + start: () => { + Container.get(HomeController); + Container.get(UsersController); + Container.get(FoldersController); + Container.get(CustomersController); + Container.get(OfficesController); + Container.get(DeedsController); + }, +}; diff --git a/src/services/CustomersService/CustomersService.ts b/src/services/CustomersService/CustomersService.ts new file mode 100644 index 00000000..0f33c62c --- /dev/null +++ b/src/services/CustomersService/CustomersService.ts @@ -0,0 +1,57 @@ +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; + +@Service() +export default class CustomersService extends BaseService { + constructor() { + super(); + } + + /** + * @description : Get all Customers + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async get() { + // const customer = await this.customersRepository.findOne(uuid); + // if (!customer) Promise.reject(new Error("Cannot get customer by uuid")); + return { response: "/api/customers > GET : All customers > Not implemented yet" }; + } + + /** + * @description : Create a new customer + * @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 { response: "/api/customers > POST : Create User > Not implemented yet" }; + } + + /** + * @description : Create a new customer + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async put() { + // const project = await this.projectRepository.create(projectEntity); + // if (!project) Promise.reject(new Error("Cannot create project")); + return { response: "/api/customers > POST : Create User > Not implemented yet" }; + } + + /** + * @description : Get a customer by uid + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async getByUid(uuid: string) { + // const customer = await this.customersRepository.findOne(uuid); + // if (!customer) Promise.reject(new Error("Cannot get customer by uuid")); + return { response: "/api/customers/:uuid > GET : User by uid > Not implemented yet" }; + } +} diff --git a/src/services/DeedsService/DeedsService.ts b/src/services/DeedsService/DeedsService.ts new file mode 100644 index 00000000..4cae5a8b --- /dev/null +++ b/src/services/DeedsService/DeedsService.ts @@ -0,0 +1,57 @@ +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; + +@Service() +export default class DeedsService extends BaseService { + constructor() { + super(); + } + + /** + * @description : Get all deeds + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async get() { + // const deed = await this.usersRepository.findOne(uuid); + // if (!deed) Promise.reject(new Error("Cannot get deed by uuid")); + return { response: "/api/deeds > GET : All deeds > Not implemented yet" }; + } + + /** + * @description : Create a new deed + * @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 { response: "/api/deeds > POST : Create User > Not implemented yet" }; + } + + /** + * @description : Create a new deed + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async put() { + // const project = await this.projectRepository.create(projectEntity); + // if (!project) Promise.reject(new Error("Cannot create project")); + return { response: "/api/deeds > POST : Create User > Not implemented yet" }; + } + + /** + * @description : Get a deed by uid + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async getByUid(uuid: string) { + // const deed = await this.usersRepository.findOne(uuid); + // if (!deed) Promise.reject(new Error("Cannot get deed by uuid")); + return { response: "/api/deeds/:uuid > GET : User by uid > Not implemented yet" }; + } +} diff --git a/src/services/FoldersService/FoldersService.ts b/src/services/FoldersService/FoldersService.ts new file mode 100644 index 00000000..8944dc9a --- /dev/null +++ b/src/services/FoldersService/FoldersService.ts @@ -0,0 +1,57 @@ +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; + +@Service() +export default class FoldersService extends BaseService { + constructor() { + super(); + } + + /** + * @description : Get all folders + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async get() { + // const folder = await this.foldersRepository.findOne(uuid); + // if (!folder) Promise.reject(new Error("Cannot get folder by uuid")); + return { response: "/api/folders > GET : All folders > Not implemented yet" }; + } + + /** + * @description : Create a new folder + * @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 { response: "/api/folders > POST : Create folder > Not implemented yet" }; + } + + /** + * @description : Create a new folder + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async put() { + // const project = await this.projectRepository.create(projectEntity); + // if (!project) Promise.reject(new Error("Cannot create project")); + return { response: "/api/folders > POST : Create folder > Not implemented yet" }; + } + + /** + * @description : Get a folder by uid + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async getByUid(uuid: string) { + // const folder = await this.foldersRepository.findOne(uuid); + // if (!folder) Promise.reject(new Error("Cannot get folder by uuid")); + return { response: "/api/folders/:uuid > GET : folder by uid > Not implemented yet" }; + } +} diff --git a/src/services/OfficesService/OfficesService.ts b/src/services/OfficesService/OfficesService.ts new file mode 100644 index 00000000..2aa74ef6 --- /dev/null +++ b/src/services/OfficesService/OfficesService.ts @@ -0,0 +1,58 @@ +// import ProjectsRepository from "@Common/repositories/projects/ProjectsRepository"; +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; + +@Service() +export default class OfficesService extends BaseService { + constructor() { + super(); + } + + /** + * @description : Get all office + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async get() { + // const office = await this.usersRepository.findOne(uuid); + // if (!office) Promise.reject(new Error("Cannot get office by uuid")); + return { response: "/api/office > GET : All office > Not implemented yet" }; + } + + /** + * @description : Create a new office + * @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 { response: "/api/office > POST : Create User > Not implemented yet" }; + } + + /** + * @description : Create a new office + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async put() { + // const project = await this.projectRepository.create(projectEntity); + // if (!project) Promise.reject(new Error("Cannot create project")); + return { response: "/api/office > POST : Create User > Not implemented yet" }; + } + + /** + * @description : Get a office by uid + * @returns : T + * @throws {Error} If project cannot be created + * @param : projectEntity: Partial + */ + public async getByUid(uuid: string) { + // const office = await this.usersRepository.findOne(uuid); + // if (!office) Promise.reject(new Error("Cannot get office by uuid")); + return { response: "/api/office/:uuid > GET : User by uid > Not implemented yet" }; + } +} diff --git a/src/services/UsersService/UsersService.ts b/src/services/UsersService/UsersService.ts index 49d7c24b..401f7daa 100644 --- a/src/services/UsersService/UsersService.ts +++ b/src/services/UsersService/UsersService.ts @@ -1,4 +1,3 @@ -// import ProjectsRepository from "@Common/repositories/projects/ProjectsRepository"; import BaseService from "@Services/BaseService"; import { Service } from "typedi"; @@ -19,7 +18,7 @@ export default class UsersService extends BaseService { // if (!user) Promise.reject(new Error("Cannot get user by uuid")); return { response: "/api/users > GET : All users > Not implemented yet" }; } - + /** * @description : Create a new user * @returns : T diff --git a/tsconfig.json b/tsconfig.json index 06ff79ce..0d461c21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -91,7 +91,7 @@ "include": [ "**/*.ts", "**/*.tsx", - "src/app/api/UserController.ts" + "src/app/api/UsersController.ts" ], "exclude": [ "node_modules"