location update optimized with schema changes and geoJson Compatability testing endpoint with encrypted key authorization

This commit is contained in:
Shibi Chakkaravarthy
2026-04-17 14:15:11 +05:30
parent b44abf9c88
commit 92769cfd38
19 changed files with 459 additions and 27 deletions
-15
View File
@@ -1,16 +1,5 @@
import { model, Schema, Types } from "mongoose";
const coordinatesSchema = new Schema({
latitude: {
type: Number,
required: true,
},
longitude: {
type: Number,
required: true,
},
});
const schema = new Schema({
name: {
type: String,
@@ -41,10 +30,6 @@ const schema = new Schema({
type: Date,
required: true,
},
coordinates: {
type: coordinatesSchema,
required: true,
},
type: {
type: String,
required: true,
+20 -1
View File
@@ -1,5 +1,24 @@
import { model, Schema, Types } from "mongoose";
import { locationSchema } from "../../helpers";
const schema = new Schema({});
const schema = new Schema({
user: {
type: Types.ObjectId,
required: true,
ref: "user",
},
coordinates: locationSchema,
createdOn: {
type: Date,
required: true,
},
venue: {
type: Types.ObjectId,
required: false,
ref: "venue",
},
});
schema.index({ coordinates: "2dsphere" });
export default model("location", schema);
+14 -3
View File
@@ -1,8 +1,14 @@
import Model from "./model.js";
import { coordinatesToGeoJson } from "../../helpers/geoJson.helper.js";
import dayjs from "dayjs";
// Create
export const createLocation = async (data) => {
return await Model.create(data);
const geoJson = coordinatesToGeoJson(data.coordinates);
return await Model.create({
...data,
coordinates: geoJson,
createdOn: dayjs().toISOString(),
});
};
// Read (Get by ID)
@@ -13,7 +19,12 @@ export const getLocationById = async (id) => {
// Read (Get by Query)
export const getLocationByQuery = async (query) => {
return await Model.findOne(query);
}
};
// Read (Get by Radius)
export const getLocationByRadius = async (radius) => {
return await Model.find(query);
};
// Read (Get all)
export const getAllLocations = async () => {
+63 -1
View File
@@ -1,5 +1,67 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
const contactPersonSchema = new Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
mobile: {
type: String,
required: true,
},
designation: {
type: String,
required: true,
},
});
const schema = new Schema({
name: {
type: String,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
email: {
type: String,
required: true,
},
mobile: {
type: String,
required: true,
},
address: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
pincode: {
type: String,
required: true,
},
isActive: {
type: Boolean,
default: true,
},
contactPersons: [contactPersonSchema],
});
export default model("partner", schema);
+63 -1
View File
@@ -1,5 +1,67 @@
import { model, Schema, Types } from "mongoose";
const schema = new Schema({});
const contactPersonSchema = new Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
mobile: {
type: String,
required: true,
},
designation: {
type: String,
required: true,
},
});
const schema = new Schema({
name: {
type: String,
required: true,
},
createdBy: {
type: Types.ObjectId,
required: true,
ref: "user",
},
createdOn: {
type: Date,
required: true,
},
email: {
type: String,
required: false,
},
mobile: {
type: String,
required: true,
},
address: {
type: String,
required: true,
},
city: {
type: String,
required: true,
},
state: {
type: String,
required: true,
},
pincode: {
type: String,
required: true,
},
isActive: {
type: Boolean,
default: true,
},
contactPersons: [contactPersonSchema],
});
export default model("vendor", schema);
+46
View File
@@ -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);
+31
View File
@@ -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);
};