-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathget.ts
More file actions
55 lines (45 loc) · 1.38 KB
/
Copy pathget.ts
File metadata and controls
55 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { NextApiResponse } from 'next';
import logger from '@/lib/logger';
import { prisma } from '@/prisma';
import { type NextApiRequestWithUser } from '@/features/auth/types';
import { withAuth } from '@/features/auth/utils/withAuth';
async function submission(req: NextApiRequestWithUser, res: NextApiResponse) {
const userId = req.userId;
const rawId = req.query.id;
const id = Array.isArray(rawId) ? rawId[0] : rawId;
if (!id || typeof id !== 'string' || id.trim() === '') {
return res.status(400).json({
message: 'Listing ID is required in the query parameters.',
});
}
const cleanId = id.trim();
try {
const result = await prisma.submission.findFirst({
where: {
userId,
listingId: cleanId,
},
omit: {
ai: true,
label: true,
notes: true,
paymentDetails: true,
},
});
if (!result) {
return res.status(404).json({
message: `Submission for user=${userId} and listingId=${id} not found.`,
});
}
return res.status(200).json(result);
} catch (error: any) {
logger.error(
`Error fetching submission for user=${userId} and listingId=${id}: ${error.message}`,
);
return res.status(500).json({
error: error.message,
message: 'Error occurred while getting the submission.',
});
}
}
export default withAuth(submission);