-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5732391
commit 4a7cb67
Showing
6 changed files
with
195 additions
and
0 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,36 @@ | ||
import AbstractController from "@core/Controller"; | ||
import EquipmentsService from "@src/Equipments/Services/EquipmentsService"; | ||
import Equipment from "@src/Equipments/Models/Equipment"; | ||
|
||
class EquipmentsController extends AbstractController { | ||
|
||
/** @private @static Singleton instance */ | ||
private static _instance: AbstractController; | ||
|
||
/** @public PersonsService */ | ||
service: EquipmentsService; | ||
|
||
/** @public Model */ | ||
entity: Equipment; | ||
|
||
name: string = "Equipment"; | ||
|
||
constructor() { | ||
super(); | ||
this.entity = Equipment.getInstance(); | ||
this.service = EquipmentsService.getInstance(this.entity); | ||
} | ||
|
||
/** | ||
* @public @static @method getInstance Create the singleton instance if not existing | ||
* @return {EquipmentsController} Controller singleton constructor | ||
*/ | ||
public static getInstance(): AbstractController { | ||
if (typeof EquipmentsController._instance === "undefined") { | ||
EquipmentsController._instance = new EquipmentsController(); | ||
} | ||
return EquipmentsController._instance; | ||
} | ||
} | ||
|
||
export default EquipmentsController; |
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,99 @@ | ||
import mongoose, {Schema} from "mongoose"; | ||
import AbstractModel from "@core/Model"; | ||
import type {DbProvider} from "@database/DatabaseDomain"; | ||
import {EquipmentSchema} from "@src/Equipments/Schemas/EquipmentSchema"; | ||
import EquipmentsService from "@src/Equipments/Services/EquipmentsService"; | ||
|
||
class Equipment extends AbstractModel { | ||
|
||
/** @protected @static Singleton instance */ | ||
protected static _instance: Equipment; | ||
|
||
/** @public @static Model singleton instance constructor */ | ||
public static getInstance(): Equipment { | ||
if (Equipment._instance === undefined) { | ||
Equipment._instance = new Equipment(); | ||
|
||
//events must be defined before assigning to mongoose : https://mongoosejs.com/docs/middleware.html#defining | ||
Equipment._instance.registerEvents(); | ||
|
||
//Setting virtuals | ||
//Equipment._instance.schema.virtual("Equipment").get( function () { return Equipment._instance.modelName }); | ||
|
||
Equipment._instance.initSchema(); | ||
|
||
//Index | ||
//Equipment._instance.schema.index({ "Equipment.Equipment":1}); | ||
} | ||
return Equipment._instance; | ||
} | ||
|
||
/** @public Model lastName */ | ||
modelName: string = 'Equipment'; | ||
|
||
/** @public Collection Name in database*/ | ||
collectionName: string = 'Equipments'; | ||
|
||
/** @public Connection mongoose */ | ||
connection: mongoose.Connection; | ||
provider: DbProvider; | ||
service: EquipmentsService; | ||
mongooseModel: mongoose.Model<any>; | ||
|
||
/** @public Database schema */ | ||
schema: Schema = | ||
new Schema<EquipmentSchema>({}, | ||
{ | ||
toJSON: {virtuals: true}, | ||
timestamps: true, | ||
}); | ||
|
||
/** @abstract Used to return attributes and rules for each field of this entity. */ | ||
public fieldInfo: any = []; | ||
|
||
/** @abstract Set of rules that are verified for every field of this entity. */ | ||
public ruleSet: any = []; | ||
|
||
|
||
public registerIndexes(): void { | ||
return; | ||
}; | ||
|
||
public dropIndexes(): void { | ||
return; | ||
}; | ||
|
||
/** | ||
* @get the field that are searchable. | ||
* @return {Object} the field slug/names. | ||
*/ | ||
get searchSearchableFields(): object { | ||
return [""]; | ||
} | ||
|
||
/** | ||
* @public @method dataTransfertObject Format the document for the public return. | ||
* @todo faire une version qu'on a un objet adapté au document et non mandatoir sur toute les propriétés inscrite. | ||
* @param document | ||
* @return {any} | ||
*/ | ||
public dataTransfertObject(document: any) { | ||
return { | ||
_id: document._id ?? '', | ||
} | ||
} | ||
|
||
public async documentation(): Promise<any> { | ||
return ""; | ||
} | ||
|
||
|
||
/** | ||
* Register mongoose events, for now pre-save, pre-findOneAndUpdate | ||
*/ | ||
public registerEvents(): void { | ||
|
||
} | ||
} | ||
|
||
export default Equipment; |
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,33 @@ | ||
import express from "express"; | ||
import AbstractController from "@core/Controller"; | ||
import CrudRoute from "@core/CrudRoute"; | ||
import EquipmentsController from "@src/Equipments/Controllers/EquipmentsController"; | ||
|
||
class EquipmentsRoutes extends CrudRoute { | ||
|
||
controllerInstance: AbstractController = EquipmentsController.getInstance(); | ||
routerInstance: express.Router = express.Router(); | ||
routerInstanceAuthentification: express.Router = express.Router(); | ||
|
||
middlewaresDistribution: any = { | ||
all: [], | ||
createUpdate: [], | ||
create: [], | ||
update: [], | ||
delete: [], | ||
search: [], | ||
list: [], | ||
getinfo: [], | ||
getdoc: [] | ||
} | ||
|
||
public setupAdditionnalPublicRoutes(router: express.Router): express.Router { | ||
return router; | ||
} | ||
|
||
public setupAdditionnalAuthRoutes(router: express.Router): express.Router { | ||
return router; | ||
} | ||
} | ||
|
||
export {EquipmentsRoutes}; |
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 @@ | ||
import {Document} from "mongoose"; | ||
|
||
export interface EquipmentSchema extends Document { | ||
|
||
} |
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 {Service} from "@database/DatabaseDomain"; | ||
import Equipment from "@src/Equipments/Models/Equipment"; | ||
|
||
class EquipmentsService extends Service { | ||
/** @private @static Singleton instance */ | ||
private static _instance: EquipmentsService; | ||
|
||
constructor(entity: Equipment) { | ||
super(entity); | ||
} | ||
|
||
/** @public @static Singleton constructor for EquipmentsService */ | ||
public static getInstance(model: any): EquipmentsService { | ||
if (typeof EquipmentsService._instance === "undefined") { | ||
EquipmentsService._instance = new EquipmentsService(model); | ||
} | ||
return EquipmentsService._instance; | ||
} | ||
} | ||
|
||
export default EquipmentsService; |
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 @@ | ||
/**silence is golden*/ |