34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { Request, Response } from 'express';
|
|
import { UserQueryDispatcher } from '../../functions/Users/Queries/UserQueryDispatcher';
|
|
import { UserCommandDispatcher } from '../../functions/Users/Commands/UserCommandDispatcher';
|
|
import { UserExistsQuery } from '../../functions/Users/Queries/UserQuery';
|
|
|
|
export async function checkUserExists(
|
|
req: Request,
|
|
res: Response,
|
|
queryDispatcher: UserQueryDispatcher,
|
|
commandDispatcher: UserCommandDispatcher
|
|
): Promise<void> {
|
|
try {
|
|
if(!req.user || !req.user.id) {
|
|
res.status(401).json({
|
|
success: false,
|
|
message: 'Unauthorized access - user not authenticated'
|
|
});
|
|
return;
|
|
}
|
|
const id = req.user.id.toString();
|
|
const query = new UserExistsQuery(parseInt(id));
|
|
const exists = await queryDispatcher.dispatch(query);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
exists
|
|
});
|
|
} catch (error: any) {
|
|
res.status(500).json({
|
|
success: false,
|
|
message: error.message || 'Failed to check user existence'
|
|
});
|
|
}
|
|
} |