You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
6.5 KiB

const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;
const citySchema = new mongoose.Schema(
{
cityId:{type:String},
//departmentName: { type: String },
phone: { type: String, unique: true, trim: true },
office_address1: String,
officeName: { type: String },
email: { type: String },
address2: String,
pincode: { type: String },
zone: { type: String },
longitude: { type: Number, default: 0.0 },
latitude: { type: Number, default: 0.0 },
googleLocation: { type: String },
gstNo: { type: String },
city: { type: String },
location: [{ type : String}],
state: String,
country: String,
services: { password: { bcrypt: String } },
createdAt: {
type: Date,
default: function () {
return Date.now();
},
},
createdBy: ObjectId,
updatedAt: {
type: Date,
default: function () {
return Date.now();
},
},
updatedBy: ObjectId,
},
{ versionKey: false }
);
const branchSchema = new mongoose.Schema(
{
branchId:{type:String},
phone: { type: String, unique: true, trim: true },
land_line_number: { type: String, trim: true },
office_address1: String,
officeName: { type: String },
email: { type: String },
address2: String,
pincode: { type: String },
zone: { type: String , default: "ALL"},
city: { type: String },
location: [{ type : String}],
googleLocation: { type: String },
longitude: { type: Number, default: 0.0 },
latitude: { type: Number, default: 0.0 },
googleLocation: { type: String },
state: String,
country: String,
nameoftheContactPerson: String,
services: { password: { bcrypt: String } },
createdAt: {
type: Date,
default: function () {
return Date.now();
},
},
createdBy: ObjectId,
updatedAt: {
type: Date,
default: function () {
return Date.now();
},
},
updatedBy: ObjectId,
},
{ versionKey: false }
);
const zoneSchema = new mongoose.Schema(
{
zoneId:{type:String},
officeName: { type: String },
zone: { type: String , default: "ALL"},
city: { type: String },
area: { type: String },
location: [{ type : String}],
createdAt: {
type: Date,
default: function () {
return Date.now();
},
},
createdBy: ObjectId,
updatedAt: {
type: Date,
default: function () {
return Date.now();
},
},
updatedBy: ObjectId,
},
{ versionKey: false }
);
const departmentsSchema = new mongoose.Schema(
{
adminId: String,
departmentId:{type:String},
officeName: { type: String },
desginationName: { type: String },
phone: { type: String, unique: true, trim: true },
alternativeContactNumber : { type: String },
reportingManager: { type: String, default: "Self" },
reportingManager_mobile_number : { type: String },
reportingManager_email : { type: String },
location: [{ type : String}],
firstName : { type: String },
gender: { type: String },
lastName: { type: String },
email: { type: String },
personalEmail : {type: String},
departmentName: { type: String },
address1: String,
address2: String,
pincode: { type: String },
zone: { type: String },
city: { type: String },
personal_city: { type: String },
state: String,
country: String,
picture:{type:String},
dateOfJoin : { type: String },
services: { password: { bcrypt: String } },
team_member: {
team_member: [
{
teamMemberId: { type: String },
firstName: { type: String },
phone: { type: String },
installationTeamMemId: { type: String },
password: { type: String, default: null },
status: { type: String, default: "active" },
email: { type: String },
alternativePhone: { type: String },
departmentId: String, // new
departmentName: String,
}
],
},
createdAt: {
type: Date,
default: function () {
return Date.now();
},
},
createdBy: ObjectId,
updatedAt: {
type: Date,
default: function () {
return Date.now();
},
},
updatedBy: ObjectId,
},
{ versionKey: false }
);
const teamMemberProfilePictureSchema = new Schema({
customerId: {
type: String,
unique: true,
required: true
},
picture: {
type: String, // Change the type to String
required: true,
validate: {
validator: function (value) {
const supportedFormats = ['jpg', 'jpeg', 'png'];
const fileExtension = value.split('.').pop().toLowerCase();
return supportedFormats.includes(fileExtension);
},
message: 'Picture must be a JPEG, PNG, or JPG image'
}
}
});
const companyProfilePictureSchema = new Schema({
customerId: {
type: String,
unique: true,
required: true
},
picture: {
type: String, // Change the type to String
required: true,
validate: {
validator: function (value) {
const supportedFormats = ['jpg', 'jpeg', 'png'];
const fileExtension = value.split('.').pop().toLowerCase();
return supportedFormats.includes(fileExtension);
},
message: 'Picture must be a JPEG, PNG, or JPG image'
}
}
});
const stateSchema = new mongoose.Schema({
state: { type: String, required: true, unique: true },
majorCities: { type: [String], required: true }
});
const IndianLocations = mongoose.model("IndianLocations", stateSchema);
const City = mongoose.model('City', citySchema);
const Deparments = mongoose.model('Deparments', departmentsSchema);
const Branch = mongoose.model('Branch', branchSchema);
const Zone = mongoose.model('Zone', zoneSchema);
const TeamMemberProfilePicture = mongoose.model('TeamMemberProfilePicture', teamMemberProfilePictureSchema);
const CompanyProfilePicture = mongoose.model('CompanyProfilePicture', companyProfilePictureSchema);
module.exports = { City,Deparments,Branch,TeamMemberProfilePicture,CompanyProfilePicture,Zone,IndianLocations};