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.
88 lines
2.6 KiB
88 lines
2.6 KiB
3 years ago
|
const mongoose = require("mongoose");
|
||
|
|
||
|
const Schema = mongoose.Schema;
|
||
|
const ObjectId = Schema.Types.ObjectId;
|
||
|
|
||
|
const code = Math.floor(100000 + Math.random() * 900000);
|
||
|
|
||
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User')
|
||
|
|
||
|
|
||
|
const generateSupplierId = async () => {
|
||
|
var result = await Counter.findOneAndUpdate(
|
||
|
{ _id: 'supplier_id' },
|
||
|
{ $inc: { seq: 1 } },
|
||
|
{ upsert: true, new: true }
|
||
|
);
|
||
|
|
||
|
return result.seq;
|
||
|
};
|
||
|
|
||
|
const supplierSchema = new mongoose.Schema(
|
||
|
{
|
||
|
suppliername: { type: String },
|
||
|
phone: { type: String, unique: true, trim: true },
|
||
|
supplierId: {type : String, default: null},
|
||
|
phoneVerified: { type: Boolean, default: false },
|
||
|
phoneVerificationCode: { type: Number, default: 11111 },
|
||
|
passwordResetCode: { type: Number, default: code },
|
||
|
oneTimePasswordSetFlag: { type: Boolean, default: false },
|
||
|
emails: [{ email: String, verified: { type: Boolean, default: false } }],
|
||
|
services: { password: { bcrypt: String } },
|
||
|
|
||
|
profile: {
|
||
|
role: [{ type: String, default: "supplier" }],
|
||
|
firstName: { type: String, default: null },
|
||
|
lastName: { type: String, default: null },
|
||
|
contactNumber: { type: String, default: null },
|
||
|
alternativeContactNumber : { type: String, default: null },
|
||
|
office_address: { type: String, default: null },
|
||
|
city: { type: String, default: null },
|
||
|
state: { type: String, default: null },
|
||
|
country: { type: String, default: null },
|
||
|
zip: { type: String, default: null },
|
||
|
},
|
||
|
status: {
|
||
|
type: String,
|
||
|
enum: ['accept', 'pending', 'reject'],
|
||
|
default: 'pending'
|
||
|
},
|
||
|
|
||
|
currentGPS: {
|
||
|
// It's important to define type within type field, because
|
||
|
// mongoose use "type" to identify field's object type.
|
||
|
|
||
|
gpsType: { type: String, default: "Point" },
|
||
|
// Default value is needed. Mongoose pass an empty array to
|
||
|
// array type by default, but it will fail MongoDB's pre-save
|
||
|
// validation.
|
||
|
coordinates: { type: [Number], default: [0, 0] },
|
||
|
},
|
||
|
|
||
|
isActive: Boolean,
|
||
|
tenantId: ObjectId,
|
||
|
createdAt: {
|
||
|
type: Date,
|
||
|
default: function () {
|
||
|
return Date.now();
|
||
|
},
|
||
|
},
|
||
|
createdBy: ObjectId,
|
||
|
updatedAt: {
|
||
|
type: Date,
|
||
|
default: function () {
|
||
|
return Date.now();
|
||
|
},
|
||
|
},
|
||
|
updatedBy: ObjectId,
|
||
|
},
|
||
|
{ versionKey: false }
|
||
|
);
|
||
|
|
||
|
|
||
|
|
||
|
const Supplier = mongoose.model("Supplier", supplierSchema);
|
||
|
|
||
|
|
||
|
module.exports = { Supplier, generateSupplierId}
|