2024-10-10 23:40:49 +00:00
|
|
|
import { StatusCodes } from '$lib/constants/status-codes';
|
|
|
|
|
import { unauthorizedSchema } from '$lib/server/api/common/exceptions';
|
2024-10-11 18:40:01 +00:00
|
|
|
import { createAuthCookieSchema } from '$lib/server/api/common/openapi/create-cookie-schema';
|
2024-10-10 23:40:49 +00:00
|
|
|
import { selectUserSchema } from '$lib/server/api/databases/tables/users.table';
|
|
|
|
|
import { updateProfileDto } from '$lib/server/api/dtos/update-profile.dto';
|
2024-10-11 18:40:01 +00:00
|
|
|
import { z } from '@hono/zod-openapi';
|
2024-10-10 23:40:49 +00:00
|
|
|
import { defineOpenApiOperation } from 'hono-zod-openapi';
|
|
|
|
|
import { createErrorSchema } from 'stoker/openapi/schemas';
|
|
|
|
|
|
|
|
|
|
const tags = ['IAM'];
|
|
|
|
|
|
|
|
|
|
export const iam = defineOpenApiOperation({
|
|
|
|
|
tags,
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'User profile',
|
|
|
|
|
schema: selectUserSchema,
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const updateProfile = defineOpenApiOperation({
|
|
|
|
|
tags,
|
|
|
|
|
request: {
|
|
|
|
|
json: updateProfileDto,
|
2024-10-11 18:40:01 +00:00
|
|
|
cookies: createAuthCookieSchema(),
|
|
|
|
|
headers: z.object({
|
|
|
|
|
authorization: z.string(),
|
|
|
|
|
}),
|
2024-10-10 23:40:49 +00:00
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
[StatusCodes.OK]: {
|
|
|
|
|
description: 'Updated User',
|
|
|
|
|
schema: selectUserSchema,
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNPROCESSABLE_ENTITY]: {
|
|
|
|
|
description: 'The validation error(s)',
|
|
|
|
|
schema: createErrorSchema(updateProfileDto),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
[StatusCodes.UNAUTHORIZED]: {
|
|
|
|
|
description: 'Unauthorized',
|
|
|
|
|
schema: createErrorSchema(unauthorizedSchema),
|
|
|
|
|
mediaType: 'application/json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|