89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import { auth } from '@/auth';
|
|
import { NextResponse } from 'next/server';
|
|
import { prisma } from '@/prisma';
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/user/{user}:
|
|
* get:
|
|
* description: Retrieve the information of a specific user by ID or name.
|
|
* parameters:
|
|
* - in: path
|
|
* name: user
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* description: The ID or name of the user to retrieve.
|
|
* responses:
|
|
* 200:
|
|
* description: User information retrieved successfully.
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: 'object'
|
|
* properties:
|
|
* success:
|
|
* type: 'boolean'
|
|
* default: true
|
|
* user:
|
|
* $ref: '#/components/schemas/PublicUser'
|
|
* 401:
|
|
* description: User is not authenticated.
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/ErrorResponse'
|
|
* example:
|
|
* {
|
|
* success: false,
|
|
* message: 'Not authenticated',
|
|
* }
|
|
* 404:
|
|
* description: User not found.
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/ErrorResponse'
|
|
* example:
|
|
* {
|
|
* success: false,
|
|
* message: 'User not found'
|
|
* }
|
|
*/
|
|
export const GET = auth(async function GET(req, { params }) {
|
|
if (!req.auth)
|
|
return NextResponse.json(
|
|
{ success: false, message: 'Not authenticated' },
|
|
{ status: 401 },
|
|
);
|
|
if (!req.auth.user || !req.auth.user.id)
|
|
return NextResponse.json(
|
|
{ success: false, message: 'User not found' },
|
|
{ status: 404 },
|
|
);
|
|
|
|
const requestedUser = (await params).user;
|
|
const dbUser = await prisma.user.findFirst({
|
|
where: {
|
|
OR: [{ id: requestedUser }, { name: requestedUser }],
|
|
},
|
|
});
|
|
|
|
if (!dbUser)
|
|
return NextResponse.json(
|
|
{ success: false, message: 'User not found' },
|
|
{ status: 404 },
|
|
);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
user: {
|
|
id: dbUser.id,
|
|
name: dbUser.name,
|
|
first_name: dbUser.first_name,
|
|
last_name: dbUser.last_name,
|
|
timezone: dbUser.timezone,
|
|
image: dbUser.image,
|
|
},
|
|
});
|
|
});
|