32 lines
668 B
JavaScript
32 lines
668 B
JavaScript
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);
|
|
};
|