diff --git a/src/Equipments/Controllers/EquipmentsController.ts b/src/Equipments/Controllers/EquipmentsController.ts new file mode 100644 index 00000000..5bd35618 --- /dev/null +++ b/src/Equipments/Controllers/EquipmentsController.ts @@ -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; \ No newline at end of file diff --git a/src/Equipments/Models/Equipment.ts b/src/Equipments/Models/Equipment.ts new file mode 100644 index 00000000..005ed2f7 --- /dev/null +++ b/src/Equipments/Models/Equipment.ts @@ -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; + + /** @public Database schema */ + schema: Schema = + new Schema({}, + { + 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 { + return ""; + } + + + /** + * Register mongoose events, for now pre-save, pre-findOneAndUpdate + */ + public registerEvents(): void { + + } +} + +export default Equipment; \ No newline at end of file diff --git a/src/Equipments/Routes/EquipmentsRoute.ts b/src/Equipments/Routes/EquipmentsRoute.ts new file mode 100644 index 00000000..ac677957 --- /dev/null +++ b/src/Equipments/Routes/EquipmentsRoute.ts @@ -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}; \ No newline at end of file diff --git a/src/Equipments/Schemas/EquipmentSchema.ts b/src/Equipments/Schemas/EquipmentSchema.ts new file mode 100644 index 00000000..a65e52e3 --- /dev/null +++ b/src/Equipments/Schemas/EquipmentSchema.ts @@ -0,0 +1,5 @@ +import {Document} from "mongoose"; + +export interface EquipmentSchema extends Document { + +} \ No newline at end of file diff --git a/src/Equipments/Services/EquipmentsService.ts b/src/Equipments/Services/EquipmentsService.ts new file mode 100644 index 00000000..3ccbe80d --- /dev/null +++ b/src/Equipments/Services/EquipmentsService.ts @@ -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; \ No newline at end of file diff --git a/src/Equipments/index.ts b/src/Equipments/index.ts new file mode 100644 index 00000000..85606c1b --- /dev/null +++ b/src/Equipments/index.ts @@ -0,0 +1 @@ +/**silence is golden*/ \ No newline at end of file