Initialized Project with default middlewares and helpers, connected to Atlas Instance and created Swagger Setup. Created necessary DB models and authentication-authorization logic
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { model, Schema, Types } from "mongoose";
|
||||
|
||||
const schema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
hash: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
refreshToken: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
isFirstTime: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
createdOn: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default model("user", schema);
|
||||
@@ -0,0 +1,31 @@
|
||||
import Model from "./model.js";
|
||||
|
||||
// Create
|
||||
export const createUser = async (data) => {
|
||||
return await Model.create(data);
|
||||
};
|
||||
|
||||
// Read (Get by ID)
|
||||
export const getUserById = async (id) => {
|
||||
return await Model.findById(id);
|
||||
};
|
||||
|
||||
//Read (Get by query)
|
||||
export const getUserByQuery = async (query) => {
|
||||
return await Model.findOne(query);
|
||||
};
|
||||
|
||||
// Read (Get all)
|
||||
export const getAllUsers = async () => {
|
||||
return await Model.find();
|
||||
};
|
||||
|
||||
// Update
|
||||
export const updateUser = async (id, data) => {
|
||||
return await Model.findByIdAndUpdate(id, data, { new: true });
|
||||
};
|
||||
|
||||
// Aggregate
|
||||
export const aggregateUser = async (pipeline) => {
|
||||
return await Model.aggregate(pipeline);
|
||||
};
|
||||
Reference in New Issue
Block a user