Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(misc) : 3404 - monstache integration POC #4377

Merged
merged 16 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ module.exports = {
ENABLE_2FA: false,
LOG_LEVEL: "info", // error, warn, info, http, debug
DO_MIGRATION: true,
ENABLE_MONGOOSE_ELASTIC: false,
};
1 change: 1 addition & 0 deletions api/config/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
TASK_QUEUE_PREFIX: "production",
MAIL_TRANSPORT: "BREVO",
ENABLE_2FA: true,
ENABLE_MONGOOSE_ELASTIC: true,
...secrets,
};
5 changes: 4 additions & 1 deletion api/src/models/PlanDeTransport/ligneBus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import mongooseElastic from "@selego/mongoose-elastic";
import patchHistory from "mongoose-patch-history";
Expand Down Expand Up @@ -46,7 +47,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

schema.index({ cohort: 1 });
schema.index({ cohort: 1, busId: 1 }, { unique: true });
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/PlanDeTransport/ligneToPoint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -35,7 +36,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type LigneToPointType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type LigneToPointDocument<T = {}> = DocumentExtended<LigneToPointType & T>;
Expand Down
7 changes: 5 additions & 2 deletions api/src/models/PlanDeTransport/modificationBus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mongoose, { InferSchemaType, Schema } from "mongoose";
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";

Expand Down Expand Up @@ -40,7 +41,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type ModificationBusType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type ModificationBusDocument<T = {}> = DocumentExtended<ModificationBusType & T>;
Expand Down
7 changes: 5 additions & 2 deletions api/src/models/PlanDeTransport/planTransport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mongoose, { InferSchemaType, Schema } from "mongoose";
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";

Expand Down Expand Up @@ -49,7 +50,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

schema.index({ ligneDeBusId: 1 });

Expand Down
5 changes: 4 additions & 1 deletion api/src/models/PlanDeTransport/pointDeRassemblement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { InferSchemaType, Schema } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -35,7 +36,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type PointDeRassemblementType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type PointDeRassemblementDocument<T = {}> = DocumentExtended<PointDeRassemblementType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/PlanDeTransport/tableDeRepartition.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import mongooseElastic from "@selego/mongoose-elastic";
import esClient from "../../es";
Expand Down Expand Up @@ -34,7 +35,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type TableDeRepartitionType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type TableDeRepartitionDocument<T = {}> = DocumentExtended<TableDeRepartitionType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/alerteMessage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema } from "mongoose";
import mongooseElastic from "@selego/mongoose-elastic";
import esClient from "../es";
Expand Down Expand Up @@ -35,7 +36,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

export type AlerteMessageDocument<T = {}> = DocumentExtended<AlerteMessageType & T>;
type SchemaExtended = AlerteMessageDocument & UserExtension;
Expand Down
6 changes: 5 additions & 1 deletion api/src/models/application.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -45,7 +46,10 @@ schema.plugin(patchHistory, {
},
excludes: ["/updatedAt"],
});
schema.plugin(mongooseElastic(esClient), MODELNAME);

if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type ApplicationType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type ApplicationDocument<T = {}> = DocumentExtended<ApplicationType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/cle/classe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose from "mongoose";
import patchHistory from "mongoose-patch-history";

Expand Down Expand Up @@ -93,7 +94,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

export type ClasseDocument<T = {}> = DocumentExtended<
ClasseType & {
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/cle/etablissement.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema } from "mongoose";
import patchHistory from "mongoose-patch-history";

Expand Down Expand Up @@ -51,7 +52,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

export type EtablissementDocument<T = {}> = DocumentExtended<EtablissementType & T>;
type SchemaExtended = EtablissementDocument & UserExtension;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/cohesionCenter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -40,7 +41,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

export type CohesionCenterDocument<T = {}> = DocumentExtended<CohesionCenterType & T>;
type SchemaExtended = CohesionCenterDocument & UserExtension;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/contract.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -40,7 +41,9 @@ schema.plugin(patchHistory, {
excludes: ["/parent1Token", "/projectManagerToken", "/structureManagerToken", "/parent2Token", "/youngContractToken", "/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type ContractType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type ContractDocument<T = {}> = DocumentExtended<ContractType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/departmentService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";

Expand Down Expand Up @@ -41,7 +42,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type DepartmentServiceType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type DepartmentServiceDocument<T = {}> = DocumentExtended<DepartmentServiceType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/email.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import mongooseElastic from "@selego/mongoose-elastic";
import esClient from "../es";
Expand All @@ -11,7 +12,9 @@ const MODELNAME = "email";

const schema = new Schema(EmailSchema);

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type EmailType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type EmailDocument<T = {}> = DocumentExtended<EmailType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/inscriptionGoal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -35,7 +36,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type InscriptionGoalType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type InscriptionGoalDocument<T = {}> = DocumentExtended<InscriptionGoalType & T>;
Expand Down
6 changes: 5 additions & 1 deletion api/src/models/mission.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { InferSchemaType } from "mongoose";
import mongooseElastic from "@selego/mongoose-elastic";
import patchHistory from "mongoose-patch-history";
Expand Down Expand Up @@ -40,7 +41,10 @@ schema.plugin(patchHistory, {
},
excludes: ["/updatedAt"],
});
schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["jvaRawData"] }), MODELNAME);

if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["jvaRawData"] }), MODELNAME);
}

type MissionType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type MissionDocument<T = {}> = DocumentExtended<MissionType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/missionAPI.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -35,7 +36,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient), MODELNAME);
}

type MissionAPIType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type MissionAPIDocument<T = {}> = DocumentExtended<MissionAPIType & T>;
Expand Down
47 changes: 25 additions & 22 deletions api/src/models/referent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema } from "mongoose";
import patchHistory from "mongoose-patch-history";
import bcrypt from "bcryptjs";
Expand Down Expand Up @@ -88,28 +89,30 @@ schema.plugin(patchHistory, {
],
});

schema.plugin(
mongooseElastic(esClient, {
selectiveIndexing: true,
ignore: [
"password",
"lastLogoutAt",
"passwordChangedAt",
"nextLoginAttemptIn",
"forgotPasswordResetToken",
"forgotPasswordResetExpires",
"invitationToken",
"invitationExpires",
"loginAttempts",
"attempts2FA",
"updatedAt",
"lastActivityAt",
"token2FA",
"token2FAExpires",
],
}),
MODELNAME,
);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(
mongooseElastic(esClient, {
selectiveIndexing: true,
ignore: [
"password",
"lastLogoutAt",
"passwordChangedAt",
"nextLoginAttemptIn",
"forgotPasswordResetToken",
"forgotPasswordResetExpires",
"invitationToken",
"invitationExpires",
"loginAttempts",
"attempts2FA",
"updatedAt",
"lastActivityAt",
"token2FA",
"token2FAExpires",
],
}),
MODELNAME,
);
}

schema.set("toObject", { virtuals: true });
schema.set("toJSON", { virtuals: true });
Expand Down
6 changes: 4 additions & 2 deletions api/src/models/schoolRAMSES.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -34,8 +35,9 @@ schema.plugin(patchHistory, {
},
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["raw_data"] }), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["raw_data"] }), MODELNAME);
}

type SchoolRAMSESType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type SchoolRAMSESDocument<T = {}> = DocumentExtended<SchoolRAMSESType & T>;
Expand Down
5 changes: 4 additions & 1 deletion api/src/models/sessionPhase1.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema } from "mongoose";
import mongooseElastic from "@selego/mongoose-elastic";
import patchHistory from "mongoose-patch-history";
Expand Down Expand Up @@ -58,7 +59,9 @@ schema.plugin(patchHistory, {
excludes: ["/updatedAt"],
});

schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["team"] }), MODELNAME);
if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["team"] }), MODELNAME);
}

schema.index({ cohesionCenterId: 1 });

Expand Down
6 changes: 5 additions & 1 deletion api/src/models/structure.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "config";
import mongoose, { Schema, InferSchemaType } from "mongoose";
import patchHistory from "mongoose-patch-history";
import mongooseElastic from "@selego/mongoose-elastic";
Expand Down Expand Up @@ -40,7 +41,10 @@ schema.plugin(patchHistory, {
},
excludes: ["/updatedAt"],
});
schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["jvaRawData"] }), MODELNAME);

if (config.get("ENABLE_MONGOOSE_ELASTIC")) {
schema.plugin(mongooseElastic(esClient, { selectiveIndexing: true, ignore: ["jvaRawData"] }), MODELNAME);
}

type StructureType = InterfaceExtended<InferSchemaType<typeof schema>>;
export type StructureDocument<T = {}> = DocumentExtended<StructureType & T>;
Expand Down
Loading
Loading