location update optimized with schema changes and geoJson Compatability testing endpoint with encrypted key authorization
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user