-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathroute.ts
More file actions
82 lines (80 loc) · 1.95 KB
/
Copy pathroute.ts
File metadata and controls
82 lines (80 loc) · 1.95 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { authSessionWithJWT } from '@/services/backend/auth';
import { jsonRes } from '@/services/backend/response';
import { devboxDB } from '@/services/db/init';
import { getRegionUid } from '@/utils/env';
import { NextRequest } from 'next/server';
import { z } from 'zod';
export const dynamic = 'force-dynamic';
export async function GET(req: NextRequest) {
try {
const headerList = req.headers;
const { payload } = await authSessionWithJWT(headerList);
const _uid = req.nextUrl.searchParams.get('uid');
const uidResult = z.string().uuid().safeParse(_uid);
if (!uidResult.success) {
return jsonRes({
code: 400,
error: 'Invalid uid'
});
}
const uid = uidResult.data;
const regionUid = getRegionUid();
const templateRepository = await devboxDB.templateRepository.findUnique({
where: {
uid,
isDeleted: false,
regionUid
},
select: {
templates: {
where: {
isDeleted: false
},
select: {
name: true,
uid: true
}
},
name: true,
description: true,
uid: true,
isPublic: true,
iconId: true,
icon: true,
// organizationUid: true,
organization: {
select: {
uid: true,
isDeleted: true
}
},
templateRepositoryTags: {
select: {
tag: true
}
}
}
});
if (
!templateRepository ||
(!templateRepository.isPublic &&
templateRepository.organization.isDeleted === false &&
templateRepository.organization.uid !== payload.organizationUid)
) {
return jsonRes({
code: 404,
error: 'Template not found'
});
}
return jsonRes({
data: {
templateRepository
}
});
} catch (err: any) {
return jsonRes({
code: 500,
error: err
});
}
}