location update optimized with schema changes and geoJson Compatability testing endpoint with encrypted key authorization
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { model, Schema, Types } from "mongoose";
|
||||
import { locationSchema } from "../../helpers";
|
||||
|
||||
const schema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
createdBy: {
|
||||
type: Types.ObjectId,
|
||||
required: true,
|
||||
ref: "user",
|
||||
},
|
||||
createdOn: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
location: locationSchema,
|
||||
category: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: "OWN",
|
||||
enum: ["OWN", "PARTNER", "VENDOR", "CLIENT", "DISTRIBUTOR"],
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: [
|
||||
"HQ",
|
||||
"BRANCH",
|
||||
"WAREHOUSE",
|
||||
"VENDOR",
|
||||
"PARTNER",
|
||||
"DISTRIBUTOR",
|
||||
"CLIENT",
|
||||
],
|
||||
},
|
||||
entity: {
|
||||
type: Types.ObjectId,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
schema.index({ location: "2dsphere" });
|
||||
|
||||
export default model("venue", schema);
|
||||
@@ -0,0 +1,31 @@
|
||||
import Model from "./model.js";
|
||||
|
||||
// Create
|
||||
export const createVenue = async (data) => {
|
||||
return await Model.create(data);
|
||||
};
|
||||
|
||||
// Read (Get by ID)
|
||||
export const getVenueById = async (id) => {
|
||||
return await Model.findById(id);
|
||||
};
|
||||
|
||||
// Read (Get by Query)
|
||||
export const getVenueByQuery = async (query) => {
|
||||
return await Model.findOne(query);
|
||||
}
|
||||
|
||||
// Read (Get all)
|
||||
export const getAllVenues = async () => {
|
||||
return await Model.find();
|
||||
};
|
||||
|
||||
// Update
|
||||
export const updateVenue = async (id, data) => {
|
||||
return await Model.findByIdAndUpdate(id, data, { new: true });
|
||||
};
|
||||
|
||||
// Aggregate
|
||||
export const aggregateVenue = async (pipeline) => {
|
||||
return await Model.aggregate(pipeline);
|
||||
};
|
||||
Reference in New Issue
Block a user