req for add and remove employee

main
alex 2024-01-21 19:26:45 +01:00
parent 511e969df3
commit 9c687d355c
2 changed files with 26 additions and 3 deletions

View File

@ -299,8 +299,6 @@ export async function UnlinkGoogleCalendar(req: Request, res: Response) {
// request to termin planner to remove google account
console.log("test", userSession.user_id, deleteCalendars);
axios
.post(`${process.env.TERMIN_PLANNER_URL}/removeGoogleAccount` as string, {
userId: userSession.user_id,

View File

@ -15,6 +15,7 @@ import {
import User from "../models/user";
import { Roles } from "../utils/constants";
import Store from "../models/store";
import axios from "axios";
export async function AddEmployee(req: Request, res: Response) {
try {
@ -100,8 +101,10 @@ export async function AddEmployee(req: Request, res: Response) {
// create user
const userId = newUserId();
await User.create({
user_id: newUserId(),
user_id: userId,
store_id: storeId,
role: Roles.Worker,
account_name: accountName,
@ -111,6 +114,17 @@ export async function AddEmployee(req: Request, res: Response) {
calendar_min_earliest_booking_time: calendarMinEarliestBookingTime,
})
.then(() => {
// add user to termin planner
axios
.post(`${process.env.TERMIN_PLANNER_URL}/addUser` as string, {
userId: userId,
pass: process.env.TERMIN_PLANNER_AUTHORIZATION_PASSWORD as string,
})
.then((res) => console.log(res))
.catch((err) => {
logger.info("err %s", err);
});
res.status(200).send({ msg: "success" });
})
.catch((err) => {
@ -361,6 +375,17 @@ export async function DeleteEmployee(req: Request, res: Response) {
},
})
.then(() => {
// remove user from termin planner
axios
.post(`${process.env.TERMIN_PLANNER_URL}/removeUser` as string, {
userId: userId,
pass: process.env.TERMIN_PLANNER_AUTHORIZATION_PASSWORD as string,
})
.then((res) => console.log(res))
.catch((err) => {
logger.info("err %s", err);
});
res.status(200).send({ msg: "success" });
})
.catch((err) => {