location controller updated with heading and created new models and controllers for remaining modules
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
import dayjs from "dayjs";
|
||||
import mongoose from "mongoose";
|
||||
import { coordinatesToGeoJson } from "../helpers/geoJson.helper.js";
|
||||
import bcrypt from "bcryptjs";
|
||||
import bcrypt from "bcrypt";
|
||||
|
||||
export const createEmployee = async (req, res) => {
|
||||
const session = await mongoose.startSession();
|
||||
@@ -41,7 +41,7 @@ export const createEmployee = async (req, res) => {
|
||||
throw { code: 400, message: "ID already assigned for Another Employee" };
|
||||
}
|
||||
|
||||
const employee = await User.create(
|
||||
const [employee] = await User.create(
|
||||
[
|
||||
{
|
||||
name,
|
||||
@@ -49,11 +49,15 @@ export const createEmployee = async (req, res) => {
|
||||
hash,
|
||||
createdOn: dayjs().toISOString(),
|
||||
createdBy: user.id,
|
||||
isFirstTime: true,
|
||||
isActive: true,
|
||||
},
|
||||
],
|
||||
{ session },
|
||||
);
|
||||
|
||||
console.log("EMPLOYEE", employee);
|
||||
|
||||
const profile = await Profile.create(
|
||||
[
|
||||
{
|
||||
@@ -83,8 +87,13 @@ export const createEmployee = async (req, res) => {
|
||||
],
|
||||
{ session },
|
||||
);
|
||||
await session.commitTransaction();
|
||||
session.endSession();
|
||||
res.status(200).json({ result: access });
|
||||
} catch (error) {
|
||||
console.log("createEmployee Error", error);
|
||||
await session.abortTransaction();
|
||||
session.endSession();
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user