Skip to content

Commit

Permalink
(Ajout) : domaine equipments
Browse files Browse the repository at this point in the history
  • Loading branch information
mamarmite authored and SonofaPancak committed Sep 14, 2023
1 parent 5732391 commit 4a7cb67
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Equipments/Controllers/EquipmentsController.ts
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;
99 changes: 99 additions & 0 deletions src/Equipments/Models/Equipment.ts
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;
33 changes: 33 additions & 0 deletions src/Equipments/Routes/EquipmentsRoute.ts
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};
5 changes: 5 additions & 0 deletions src/Equipments/Schemas/EquipmentSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Document} from "mongoose";

export interface EquipmentSchema extends Document {

}
21 changes: 21 additions & 0 deletions src/Equipments/Services/EquipmentsService.ts
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;
1 change: 1 addition & 0 deletions src/Equipments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**silence is golden*/

0 comments on commit 4a7cb67

Please sign in to comment.