Files
crm.stream.graff.tech/server/src/models/Company.ts
T
2023-10-12 18:29:47 +05:00

39 lines
677 B
TypeScript

import { model, Schema } from "mongoose";
const companySchema = new Schema(
{
name: {
type: String,
required: true,
unique: true,
},
},
{
timestamps: true,
toJSON: { virtuals: true },
toObject: { virtuals: true },
}
);
companySchema.virtual("users", {
ref: "User",
localField: "_id",
foreignField: "companyId",
});
companySchema.virtual("scheduledSessions", {
ref: "Scheduled_Session",
localField: "_id",
foreignField: "companyId",
});
companySchema.virtual("builds", {
ref: "Build",
localField: "_id",
foreignField: "companyId",
});
const Company = model("Company", companySchema);
export default Company;