delete employee from service activity
parent
c967496a34
commit
8f8bbbf09d
|
@ -26,6 +26,7 @@ import {
|
||||||
terminPlanerRequest,
|
terminPlanerRequest,
|
||||||
terminPlanerRequestChangeFutureBookingDays,
|
terminPlanerRequestChangeFutureBookingDays,
|
||||||
} from "../utils/terminPlaner";
|
} from "../utils/terminPlaner";
|
||||||
|
import StoreServiceActivityUsers from "../models/storeServiceActivityUsers";
|
||||||
|
|
||||||
export async function AddEmployee(req: Request, res: Response) {
|
export async function AddEmployee(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
|
@ -481,6 +482,12 @@ export async function DeleteEmployee(req: Request, res: Response) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await StoreServiceActivityUsers.destroy({
|
||||||
|
where: {
|
||||||
|
user_id: userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
storeLogger.info(store.store_id, "Deleted employee with user id:", userId);
|
storeLogger.info(store.store_id, "Deleted employee with user id:", userId);
|
||||||
|
|
||||||
res.status(200).send({ msg: "success" });
|
res.status(200).send({ msg: "success" });
|
||||||
|
|
|
@ -32,75 +32,72 @@ router.get(
|
||||||
passport.authenticate("google", {
|
passport.authenticate("google", {
|
||||||
failureRedirect: PASSPORT_FAILURE_REDIRECT_URL,
|
failureRedirect: PASSPORT_FAILURE_REDIRECT_URL,
|
||||||
}),
|
}),
|
||||||
function (req, res) {
|
async function (req, res) {
|
||||||
// Successful authentication, redirect home
|
try {
|
||||||
const sessionId = req.cookies["session"];
|
// Successful authentication, redirect home
|
||||||
|
const sessionId = req.cookies["session"];
|
||||||
|
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
logger.error("session cookie not found");
|
throw new Error("session id not found");
|
||||||
res.redirect(PASSPORT_FAILURE_REDIRECT_URL);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const accessToken = (req.user as Request & { accessToken?: string })
|
const accessToken = (req.user as Request & { accessToken?: string })
|
||||||
.accessToken;
|
.accessToken;
|
||||||
const refreshToken = (req.user as Request & { refreshToken?: string })
|
const refreshToken = (req.user as Request & { refreshToken?: string })
|
||||||
.refreshToken;
|
.refreshToken;
|
||||||
const sub = (req.user as Request & { profile?: any }).profile._json.sub; // google user id
|
const sub = (req.user as Request & { profile?: any }).profile._json.sub; // google user id
|
||||||
|
|
||||||
const googleAccountName = (req.user as Request & { profile?: any }).profile
|
const googleAccountName = (req.user as Request & { profile?: any })
|
||||||
._json.name;
|
.profile._json.name;
|
||||||
const googleAccountPicture = (req.user as Request & { profile?: any })
|
const googleAccountPicture = (req.user as Request & { profile?: any })
|
||||||
.profile._json.picture;
|
.profile._json.picture;
|
||||||
|
|
||||||
Session.findOne({
|
const userSession = await Session.findOne({
|
||||||
where: {
|
where: {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
.then(async (userSession) => {
|
|
||||||
if (!userSession) {
|
|
||||||
logger.error("user session not found");
|
|
||||||
res.redirect(PASSPORT_FAILURE_REDIRECT_URL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!userSession) {
|
||||||
|
throw new Error("user session not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
terminPlanerRequest("/api/v1/addGoogleAccount", "POST", {
|
terminPlanerRequest("/api/v1/addGoogleAccount", "POST", {
|
||||||
userId: userSession.user_id,
|
userId: userSession.user_id,
|
||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
refreshToken: refreshToken,
|
refreshToken: refreshToken,
|
||||||
sub: sub,
|
sub: sub,
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
User.findOne({
|
|
||||||
where: {
|
|
||||||
user_id: userSession.user_id,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((user) => {
|
|
||||||
if (!user) {
|
|
||||||
logger.error("user not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.google_account_name = googleAccountName;
|
|
||||||
user.google_account_picture = googleAccountPicture;
|
|
||||||
|
|
||||||
user.save().catch((err) => logger.error(err));
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
logger.error(err);
|
|
||||||
res.redirect(PASSPORT_FAILURE_REDIRECT_URL);
|
|
||||||
});
|
|
||||||
|
|
||||||
res.redirect(PASSPORT_SUCCESS_REDIRECT_URL);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
res.redirect(PASSPORT_FAILURE_REDIRECT_URL);
|
}
|
||||||
|
|
||||||
|
const user = await User.findOne({
|
||||||
|
where: {
|
||||||
|
user_id: userSession.user_id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v1/addGoogleAccount
|
if (!user) {
|
||||||
|
throw new Error("user not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
logger.error("user not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.google_account_name = googleAccountName;
|
||||||
|
user.google_account_picture = googleAccountPicture;
|
||||||
|
|
||||||
|
user.save().catch((err) => logger.error(err));
|
||||||
|
|
||||||
|
res.redirect(PASSPORT_SUCCESS_REDIRECT_URL);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
res.redirect(PASSPORT_FAILURE_REDIRECT_URL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue