-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(app): create loosely coupled engine
- Loading branch information
Showing
42 changed files
with
203 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#PRODUCTION | ||
RDBMS_DATABASE_URI="mysql://DATBASE_USER:DATABASE_PASSWORD@DATABASE_HOST:DATABASE_PORT/DATABASE_DB" | ||
NOSQL_DATABASE_URI="mongodb://DATABASE_HOST:DATABASE_PORT/DATABASE_DB" | ||
NOSQL_DATABASE_ADAPTER="mongodb" | ||
API_BASE='/v1/' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TaskEntity } from "../public/entities/task_entity"; | ||
|
||
export class TaskAdapter { | ||
taskEntity: TaskEntity; | ||
|
||
constructor(taskEntity: TaskEntity) { | ||
this.taskEntity = taskEntity; | ||
} | ||
|
||
toJson = () => JSON.stringify(this.taskEntity); | ||
} |
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Request, Response } from "express"; | ||
|
||
import { StatusCodes } from "http-status-codes"; | ||
import { TaskRepository } from "../public/repositories/task_repository"; | ||
import { TaskAdapter } from "../adapters/task_adapter"; | ||
import { TaskEntity } from "../public/entities/task_entity"; | ||
|
||
export class TasksController { | ||
taskRepository = new TaskRepository(); | ||
|
||
public addNewTask = async (req: Request, res: Response) => { | ||
const taskEntity = await this.taskRepository.create({ | ||
name: req.body.name, | ||
description: req.body.description | ||
}); | ||
|
||
const json = new TaskAdapter(taskEntity).toJson(); | ||
|
||
return res.status(StatusCodes.CREATED).json(json); | ||
}; | ||
|
||
public getTasks = async (_req: Request, res: Response) => { | ||
const taskEntities = await this.taskRepository.read({}); | ||
const taskListJson = taskEntities.map((taskEntity: TaskEntity) => new TaskAdapter(taskEntity).toJson()); | ||
|
||
return res.status(StatusCodes.OK).json(taskListJson); | ||
}; | ||
|
||
public getTaskWithID = async (req: Request, res: Response) => { | ||
const taskEntities = await this.taskRepository.read({ id: req.params.id }); | ||
let json = {}; | ||
|
||
if (taskEntities.length > 0) { | ||
json = new TaskAdapter(taskEntities[0]).toJson(); | ||
} | ||
|
||
return res.status(StatusCodes.OK).json(json); | ||
}; | ||
|
||
public updateTask = async (req: Request, res: Response) => { | ||
const taskEntity = await this.taskRepository.update({ | ||
id: req.body.id, | ||
name: req.body.name, | ||
description: req.body.description | ||
}); | ||
|
||
const json = new TaskAdapter(taskEntity).toJson(); | ||
|
||
return res.status(StatusCodes.OK).json(json); | ||
}; | ||
|
||
public deleteTask = async (req: Request, res: Response) => { | ||
await this.taskRepository.delete({ | ||
id: req.body.id | ||
}); | ||
|
||
return res.status(StatusCodes.OK).json({}); | ||
}; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ActiveRecord } from "@fractalerp/active-record-js" | ||
|
||
export interface ITaskModelDocument { | ||
name: string; | ||
description: string; | ||
} | ||
|
||
const TaskModelSchema = { | ||
name: { | ||
type: String, | ||
required: true, | ||
unique: true | ||
}, | ||
description: { | ||
type: String, | ||
default: null | ||
} | ||
}; | ||
|
||
export const TaskModel = new ActiveRecord<ITaskModelDocument>("Task", TaskModelSchema); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { NextFunction } from "express-serve-static-core"; | ||
|
||
import { TasksHomeRoute } from "../routes/tasks_home_route"; | ||
import { TasksRoute } from "../routes/tasks_route"; | ||
import { FractalJs } from "../../../app"; | ||
|
||
export class TaskRouter { | ||
public fractalJs!: FractalJs; | ||
|
||
constructor(fractalJs: FractalJs) { | ||
this.fractalJs = fractalJs; | ||
// white list public routes | ||
this.allowPublicRoutes(); | ||
// Add routes | ||
new TasksHomeRoute(fractalJs); | ||
new TasksRoute(fractalJs); | ||
} | ||
|
||
private allowPublicRoutes() { | ||
this.fractalJs.express.all( | ||
`${process.env.API_BASE}tasks/*`, async (_req: any, _res: any, next: NextFunction) => { | ||
// Add public routes not to authenticate | ||
// await this.authenticateApi(this.fractalJs, req, res, next); | ||
|
||
next(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { TasksController } from "../controllers/tasks_controller"; | ||
import { FractalJs } from "../../../app"; | ||
|
||
export class TasksRoute { | ||
public tasksController!: TasksController; | ||
|
||
public constructor(fractalJs: FractalJs) { | ||
this.tasksController = new TasksController(); | ||
const tasksEndpoint = `${process.env.API_BASE}tasks`; | ||
/* Get, Add tasks */ | ||
fractalJs.express.route(`${tasksEndpoint}`) | ||
.get(this.tasksController.getTasks) | ||
.post(this.tasksController.addNewTask); | ||
|
||
/* Task details, update and delete */ | ||
fractalJs.express.route(`${tasksEndpoint}/:id`) | ||
.get(this.tasksController.getTaskWithID) | ||
.put(this.tasksController.updateTask) | ||
.delete(this.tasksController.deleteTask); | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.