2024-10-10 23:40:49 +00:00
|
|
|
import { StatusCodes } from '$lib/constants/status-codes';
|
|
|
|
|
import { unauthorizedSchema } from '$lib/server/api/common/exceptions';
|
2024-11-06 17:49:18 +00:00
|
|
|
import { selectUserSchema } from '$lib/server/api/databases/postgres/tables/users.table';
|
2024-10-10 23:40:49 +00:00
|
|
|
import { updateProfileDto } from '$lib/server/api/dtos/update-profile.dto';
|
|
|
|
|
import { createErrorSchema } from 'stoker/openapi/schemas';
|
2024-10-14 06:10:35 +00:00
|
|
|
import { taggedAuthRoute } from '../common/openapi/create-auth-route';
|
|
|
|
|
import { changePasswordDto } from '../dtos/change-password.dto';
|
|
|
|
|
import { verifyPasswordDto } from '../dtos/verify-password.dto';
|
2024-10-10 23:40:49 +00:00
|
|
|
|
2024-10-14 06:10:35 +00:00
|
|
|
const tag = 'IAM';
|
2024-10-10 23:40:49 +00:00
|
|
|
|
2024-10-14 06:10:35 +00:00
|
|
|
export const iam = taggedAuthRoute(tag, {
|
2024-10-10 23:40:49 +00:00
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'User profile',
|
|
|
|
|
schema: selectUserSchema,
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-10-14 06:10:35 +00:00
|
|
|
export const updateProfile = taggedAuthRoute(tag, {
|
2024-10-10 23:40:49 +00:00
|
|
|
request: {
|
|
|
|
|
json: updateProfileDto,
|
|
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'Updated User',
|
|
|
|
|
schema: selectUserSchema,
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-14 06:10:35 +00:00
|
|
|
[StatusCodes.BAD_REQUEST]: {
|
2024-10-10 23:40:49 +00:00
|
|
|
description: 'The validation error(s)',
|
|
|
|
|
schema: createErrorSchema(updateProfileDto),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-14 06:10:35 +00:00
|
|
|
[StatusCodes.UNPROCESSABLE_ENTITY]: {
|
|
|
|
|
description: 'Username already in use',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const verifyPassword = taggedAuthRoute(tag, {
|
|
|
|
|
request: {
|
|
|
|
|
json: verifyPasswordDto,
|
|
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'Password verified',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.BAD_REQUEST]: {
|
|
|
|
|
description: 'The validation error(s)',
|
|
|
|
|
schema: createErrorSchema(verifyPasswordDto),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-15 01:12:05 +00:00
|
|
|
[StatusCodes.UNPROCESSABLE_ENTITY]: {
|
2024-10-14 06:10:35 +00:00
|
|
|
description: 'Incorrect password',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const updatePassword = taggedAuthRoute(tag, {
|
|
|
|
|
request: {
|
|
|
|
|
json: changePasswordDto,
|
|
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'Password updated',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.BAD_REQUEST]: {
|
|
|
|
|
description: 'The validation error(s)',
|
|
|
|
|
schema: createErrorSchema(changePasswordDto),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-15 01:12:05 +00:00
|
|
|
[StatusCodes.FORBIDDEN]: {
|
|
|
|
|
description: 'Incorrect password',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.INTERNAL_SERVER_ERROR]: {
|
|
|
|
|
description: 'Error updating password',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-14 06:10:35 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const updateEmail = taggedAuthRoute(tag, {
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'Email updated',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.BAD_REQUEST]: {
|
|
|
|
|
description: 'The validation error(s)',
|
|
|
|
|
schema: createErrorSchema(changePasswordDto),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-15 01:12:05 +00:00
|
|
|
[StatusCodes.FORBIDDEN]: {
|
|
|
|
|
description: 'Cannot change email address',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-14 06:10:35 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const logout = taggedAuthRoute(tag, {
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'Logged out',
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
2024-10-10 23:40:49 +00:00
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|