create-ej-app 11.0.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +5 -4
- package/cli.ts +9 -4
- package/package.json +1 -1
- package/template/base/package.json +14 -20
- package/template/base/src/app/not-found.tsx +1 -7
- package/template/base/terraform/artifact-registry.tf +5 -0
- package/template/base/terraform/backend-service.tf +13 -0
- package/template/base/terraform/cleanup.sh +9 -0
- package/template/base/terraform/cloudbuild.tf +70 -0
- package/template/base/terraform/cloudrun.tf +68 -0
- package/template/base/terraform/database.tf +60 -0
- package/template/base/terraform/forwarding-rule.tf +43 -0
- package/template/base/terraform/ip-address.tf +11 -0
- package/template/base/terraform/network-endpoint-group.tf +11 -0
- package/template/base/terraform/network.tf +21 -0
- package/template/base/terraform/pre.sh +3 -0
- package/template/base/terraform/providers.tf +18 -0
- package/template/base/terraform/secret.txt +11 -0
- package/template/base/terraform/setup.sh +25 -0
- package/template/base/terraform/ssl-certs.tf +32 -0
- package/template/base/terraform/target-https-proxy copy.tf +14 -0
- package/template/base/terraform/target-https-proxy.tf +14 -0
- package/template/base/terraform/terraform.tfvars +4 -0
- package/template/base/terraform/url-map.tf +23 -0
- package/template/base/terraform/variables.tf +21 -0
- package/template/old/.env.example +0 -17
- package/template/old/.eslintrc.cjs +0 -26
- package/template/old/components.json +0 -17
- package/template/old/drizzle.config.ts +0 -11
- package/template/old/next.config.mjs +0 -4
- package/template/old/package.json +0 -87
- package/template/old/postcss.config.mjs +0 -8
- package/template/old/prettier.config.mjs +0 -11
- package/template/old/public/next.svg +0 -1
- package/template/old/public/vercel.svg +0 -1
- package/template/old/src/app/(app)/dashboard/layout.tsx +0 -14
- package/template/old/src/app/(app)/dashboard/page.tsx +0 -12
- package/template/old/src/app/(app)/layout.tsx +0 -125
- package/template/old/src/app/(app)/roles/[id]/actions.ts +0 -59
- package/template/old/src/app/(app)/roles/[id]/page.tsx +0 -46
- package/template/old/src/app/(app)/roles/[id]/render.tsx +0 -264
- package/template/old/src/app/(app)/roles/[id]/validation.ts +0 -22
- package/template/old/src/app/(app)/roles/actions.ts +0 -33
- package/template/old/src/app/(app)/roles/page.tsx +0 -52
- package/template/old/src/app/(app)/roles/render.tsx +0 -80
- package/template/old/src/app/(app)/settings/actions.ts +0 -17
- package/template/old/src/app/(app)/settings/layout.tsx +0 -14
- package/template/old/src/app/(app)/settings/loading.tsx +0 -28
- package/template/old/src/app/(app)/settings/page.tsx +0 -19
- package/template/old/src/app/(app)/settings/render.tsx +0 -107
- package/template/old/src/app/(app)/settings/validation.ts +0 -5
- package/template/old/src/app/(app)/tasks/[id]/actions.ts +0 -92
- package/template/old/src/app/(app)/tasks/[id]/page.tsx +0 -59
- package/template/old/src/app/(app)/tasks/[id]/render.tsx +0 -482
- package/template/old/src/app/(app)/tasks/[id]/validation.ts +0 -18
- package/template/old/src/app/(app)/tasks/actions.ts +0 -39
- package/template/old/src/app/(app)/tasks/page.tsx +0 -59
- package/template/old/src/app/(app)/tasks/render.tsx +0 -129
- package/template/old/src/app/(app)/tasks/statusEnum.ts +0 -3
- package/template/old/src/app/(app)/users/[id]/actions.ts +0 -68
- package/template/old/src/app/(app)/users/[id]/page.tsx +0 -39
- package/template/old/src/app/(app)/users/[id]/render.tsx +0 -325
- package/template/old/src/app/(app)/users/[id]/validation.ts +0 -18
- package/template/old/src/app/(app)/users/actions.ts +0 -34
- package/template/old/src/app/(app)/users/page.tsx +0 -62
- package/template/old/src/app/(app)/users/render.tsx +0 -124
- package/template/old/src/app/(auth)/layout.tsx +0 -27
- package/template/old/src/app/(auth)/login/page.tsx +0 -49
- package/template/old/src/app/(auth)/login/render.tsx +0 -146
- package/template/old/src/app/(marketing)/layout.tsx +0 -42
- package/template/old/src/app/(marketing)/page.tsx +0 -97
- package/template/old/src/app/api/auth/[...nextauth]/route.ts +0 -7
- package/template/old/src/app/favicon.ico +0 -0
- package/template/old/src/app/globals.css +0 -76
- package/template/old/src/app/layout.tsx +0 -31
- package/template/old/src/components/app-nav-command.tsx +0 -178
- package/template/old/src/components/dark-mode-toggle.tsx +0 -43
- package/template/old/src/components/data-table/data-table-column-header.tsx +0 -91
- package/template/old/src/components/data-table/data-table-faceted-filter.tsx +0 -149
- package/template/old/src/components/data-table/data-table-loading.tsx +0 -77
- package/template/old/src/components/data-table/data-table-pagination.tsx +0 -94
- package/template/old/src/components/data-table/data-table-toolbar.tsx +0 -78
- package/template/old/src/components/data-table/data-table-types.ts +0 -17
- package/template/old/src/components/data-table/data-table-view-options.tsx +0 -59
- package/template/old/src/components/data-table/data-table.tsx +0 -301
- package/template/old/src/components/data-table/simple-data-table.tsx +0 -109
- package/template/old/src/components/empty-placeholder.tsx +0 -78
- package/template/old/src/components/heading.tsx +0 -17
- package/template/old/src/components/icons.tsx +0 -101
- package/template/old/src/components/main-nav.tsx +0 -64
- package/template/old/src/components/mobile-nav.tsx +0 -50
- package/template/old/src/components/shell.tsx +0 -13
- package/template/old/src/components/side-nav.tsx +0 -51
- package/template/old/src/components/site-footer.tsx +0 -31
- package/template/old/src/components/system-info.tsx +0 -36
- package/template/old/src/components/ui/alert-dialog.tsx +0 -141
- package/template/old/src/components/ui/avatar.tsx +0 -50
- package/template/old/src/components/ui/badge.tsx +0 -36
- package/template/old/src/components/ui/button.tsx +0 -56
- package/template/old/src/components/ui/card.tsx +0 -79
- package/template/old/src/components/ui/checkbox.tsx +0 -30
- package/template/old/src/components/ui/command.tsx +0 -155
- package/template/old/src/components/ui/dialog.tsx +0 -122
- package/template/old/src/components/ui/dropdown-menu.tsx +0 -200
- package/template/old/src/components/ui/form.tsx +0 -176
- package/template/old/src/components/ui/input.tsx +0 -25
- package/template/old/src/components/ui/label.tsx +0 -26
- package/template/old/src/components/ui/popover.tsx +0 -31
- package/template/old/src/components/ui/select.tsx +0 -160
- package/template/old/src/components/ui/separator.tsx +0 -31
- package/template/old/src/components/ui/skeleton.tsx +0 -15
- package/template/old/src/components/ui/sonner.tsx +0 -31
- package/template/old/src/components/ui/table.tsx +0 -117
- package/template/old/src/components/user-account-nav.tsx +0 -60
- package/template/old/src/components/user-avatar.tsx +0 -27
- package/template/old/src/data-access/resource.ts +0 -85
- package/template/old/src/data-access/role-permission.ts +0 -45
- package/template/old/src/data-access/role.ts +0 -105
- package/template/old/src/data-access/task.ts +0 -141
- package/template/old/src/data-access/user.ts +0 -141
- package/template/old/src/db/index.ts +0 -14
- package/template/old/src/db/schema.ts +0 -287
- package/template/old/src/env.mjs +0 -58
- package/template/old/src/hooks/use-debounce.tsx +0 -17
- package/template/old/src/hooks/use-lock-body.tsx +0 -13
- package/template/old/src/lib/auth.ts +0 -89
- package/template/old/src/lib/cn.ts +0 -4
- package/template/old/src/lib/currentUser.ts +0 -8
- package/template/old/src/lib/delay.ts +0 -2
- package/template/old/src/lib/formatDate.ts +0 -11
- package/template/old/src/lib/generateLabel.ts +0 -5
- package/template/old/src/lib/s3Client.ts +0 -156
- package/template/old/src/lib/safe-action.ts +0 -19
- package/template/old/src/lib/siteConfig.ts +0 -4
- package/template/old/src/lib/sortOrderEnum.ts +0 -2
- package/template/old/src/use-case/role-permission.ts +0 -19
- package/template/old/src/use-case/role.ts +0 -110
- package/template/old/src/use-case/task.ts +0 -166
- package/template/old/src/use-case/user.ts +0 -121
- package/template/old/tailwind.config.ts +0 -81
- package/template/old/tsconfig.json +0 -47
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { AvatarProps } from '@radix-ui/react-avatar'
|
|
2
|
-
import { FC } from 'react'
|
|
3
|
-
|
|
4
|
-
import { Icons } from '@/components/icons'
|
|
5
|
-
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
|
6
|
-
|
|
7
|
-
interface UserAvatarProps extends AvatarProps {
|
|
8
|
-
user: {
|
|
9
|
-
name?: string | null
|
|
10
|
-
image?: string | null
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const UserAvatar: FC<UserAvatarProps> = ({ user, ...props }) => {
|
|
15
|
-
return (
|
|
16
|
-
<Avatar {...props}>
|
|
17
|
-
{user.image ? (
|
|
18
|
-
<AvatarImage alt="Picture" src={user.image} />
|
|
19
|
-
) : (
|
|
20
|
-
<AvatarFallback>
|
|
21
|
-
<span className="sr-only">{user.name}</span>
|
|
22
|
-
<Icons.user className="h-4 w-4" />
|
|
23
|
-
</AvatarFallback>
|
|
24
|
-
)}
|
|
25
|
-
</Avatar>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { db } from '@/db'
|
|
2
|
-
import { Resource } from '@/db/schema'
|
|
3
|
-
import { eq, or, sql } from 'drizzle-orm'
|
|
4
|
-
|
|
5
|
-
type createResourceInput = {
|
|
6
|
-
id?: string
|
|
7
|
-
filename: string
|
|
8
|
-
key: string
|
|
9
|
-
isTemp: boolean
|
|
10
|
-
url: string
|
|
11
|
-
size: number
|
|
12
|
-
contentType: string
|
|
13
|
-
createdById?: string | null
|
|
14
|
-
|
|
15
|
-
taskId?: string | null
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const createResource = async (data: createResourceInput) => {
|
|
19
|
-
const newResource = await db
|
|
20
|
-
.insert(Resource)
|
|
21
|
-
.values({
|
|
22
|
-
...data
|
|
23
|
-
})
|
|
24
|
-
.returning({
|
|
25
|
-
id: Resource.id
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const id = newResource[0]?.id
|
|
29
|
-
|
|
30
|
-
if (!id) throw new Error('Failed to create resource')
|
|
31
|
-
|
|
32
|
-
return id
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const getResourceById = async (id: string) => {
|
|
36
|
-
return await db.query.Resource.findFirst({
|
|
37
|
-
where: eq(Resource.id, id)
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type updateResourceByIdInput = {
|
|
42
|
-
id: string
|
|
43
|
-
isTemp?: boolean
|
|
44
|
-
contentType?: string
|
|
45
|
-
size?: number
|
|
46
|
-
updatedById?: string | null
|
|
47
|
-
|
|
48
|
-
taskId?: string | null
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const updateResourceById = async (data: updateResourceByIdInput) => {
|
|
52
|
-
return await db
|
|
53
|
-
.update(Resource)
|
|
54
|
-
.set({
|
|
55
|
-
...data,
|
|
56
|
-
updatedAt: sql`now()`
|
|
57
|
-
})
|
|
58
|
-
.where(eq(Resource.id, data.id))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type updateResourceByIdsInput = {
|
|
62
|
-
ids: string[]
|
|
63
|
-
taskId?: string | null
|
|
64
|
-
updatedById?: string | null
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const updateResourceByIds = async (data: updateResourceByIdsInput) => {
|
|
68
|
-
return await db
|
|
69
|
-
.update(Resource)
|
|
70
|
-
.set({
|
|
71
|
-
...data,
|
|
72
|
-
updatedAt: sql`now()`
|
|
73
|
-
})
|
|
74
|
-
.where(or(...data.ids.map(id => eq(Resource.id, id))))
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const getResourcesByTaskId = async (taskId: string) => {
|
|
78
|
-
return await db.query.Resource.findMany({
|
|
79
|
-
where: eq(Resource.taskId, taskId)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const deleteResource = async (id: string) => {
|
|
84
|
-
return await db.delete(Resource).where(eq(Resource.id, id))
|
|
85
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { InferSelectModel, and, count, eq } from 'drizzle-orm'
|
|
2
|
-
|
|
3
|
-
import { db } from '@/db'
|
|
4
|
-
import { RolePermission } from '@/db/schema'
|
|
5
|
-
|
|
6
|
-
export type RolePermissionType = InferSelectModel<typeof RolePermission>
|
|
7
|
-
|
|
8
|
-
export const checkForRolePermission = async (
|
|
9
|
-
roleId: string,
|
|
10
|
-
permission: RolePermissionType['permission']
|
|
11
|
-
) => {
|
|
12
|
-
const c = await db
|
|
13
|
-
.select({ count: count() })
|
|
14
|
-
.from(RolePermission)
|
|
15
|
-
.where(
|
|
16
|
-
and(
|
|
17
|
-
eq(RolePermission.roleId, roleId),
|
|
18
|
-
eq(RolePermission.permission, permission)
|
|
19
|
-
)
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
return !!c?.[0]?.count
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type createRolePermissionsInput = {
|
|
26
|
-
roleId: string
|
|
27
|
-
permissions: RolePermissionType['permission'][]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const createRolePermissions = async (
|
|
31
|
-
data: createRolePermissionsInput
|
|
32
|
-
) => {
|
|
33
|
-
return await db.insert(RolePermission).values(
|
|
34
|
-
data.permissions.map(p => ({
|
|
35
|
-
roleId: data.roleId,
|
|
36
|
-
permission: p
|
|
37
|
-
}))
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const deleteRolePermissionsByRoleId = async (roleId: string) => {
|
|
42
|
-
return await db
|
|
43
|
-
.delete(RolePermission)
|
|
44
|
-
.where(eq(RolePermission.roleId, roleId))
|
|
45
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { InferSelectModel, asc, count, desc, eq, ilike, sql } from 'drizzle-orm'
|
|
2
|
-
|
|
3
|
-
import { db } from '@/db'
|
|
4
|
-
import { Role } from '@/db/schema'
|
|
5
|
-
import { type SortOrderEnum } from '@/lib/sortOrderEnum'
|
|
6
|
-
|
|
7
|
-
export type RoleType = InferSelectModel<typeof Role>
|
|
8
|
-
|
|
9
|
-
type getRolesInput = {
|
|
10
|
-
page: number
|
|
11
|
-
limit: number
|
|
12
|
-
sortBy?: keyof RoleType
|
|
13
|
-
sortOrder?: SortOrderEnum
|
|
14
|
-
filters?: {
|
|
15
|
-
name?: string
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const getRoles = async ({
|
|
20
|
-
page,
|
|
21
|
-
limit,
|
|
22
|
-
sortBy,
|
|
23
|
-
sortOrder,
|
|
24
|
-
filters
|
|
25
|
-
}: getRolesInput) => {
|
|
26
|
-
const where = filters?.name
|
|
27
|
-
? ilike(Role.name, `%${filters.name}%`)
|
|
28
|
-
: undefined
|
|
29
|
-
|
|
30
|
-
const [roles, total] = await Promise.all([
|
|
31
|
-
db.query.Role.findMany({
|
|
32
|
-
columns: {
|
|
33
|
-
id: true,
|
|
34
|
-
name: true,
|
|
35
|
-
createdAt: true,
|
|
36
|
-
updatedAt: true
|
|
37
|
-
},
|
|
38
|
-
where,
|
|
39
|
-
orderBy: [
|
|
40
|
-
sortOrder === 'asc'
|
|
41
|
-
? asc(Role[sortBy || 'createdAt'])
|
|
42
|
-
: desc(Role[sortBy || 'createdAt'])
|
|
43
|
-
],
|
|
44
|
-
offset: (page - 1) * limit,
|
|
45
|
-
limit
|
|
46
|
-
}),
|
|
47
|
-
db
|
|
48
|
-
.select({
|
|
49
|
-
count: count()
|
|
50
|
-
})
|
|
51
|
-
.from(Role)
|
|
52
|
-
.where(where)
|
|
53
|
-
])
|
|
54
|
-
|
|
55
|
-
return { roles, total: total[0]?.count || 0 }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const getRoleByIdWithPermissions = async (id: string) => {
|
|
59
|
-
return await db.query.Role.findFirst({
|
|
60
|
-
where: eq(Role.id, id),
|
|
61
|
-
with: {
|
|
62
|
-
permissions: true
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
type createRoleInput = {
|
|
68
|
-
name: string
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const createRole = async (data: createRoleInput) => {
|
|
72
|
-
const newRole = await db.insert(Role).values(data).returning({
|
|
73
|
-
id: Role.id
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const id = newRole[0]?.id
|
|
77
|
-
if (!id) throw new Error('Failed to create role')
|
|
78
|
-
|
|
79
|
-
return id
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
type updateRoleInput = createRoleInput & {
|
|
83
|
-
id: string
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const updateRole = async (data: updateRoleInput) => {
|
|
87
|
-
return await db
|
|
88
|
-
.update(Role)
|
|
89
|
-
.set({ ...data, updatedAt: sql`now()` })
|
|
90
|
-
.where(eq(Role.id, data.id))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export const deleteRole = async (id: string) => {
|
|
94
|
-
return await db.delete(Role).where(eq(Role.id, id))
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const getRolesMini = async () => {
|
|
98
|
-
return await db.query.Role.findMany({
|
|
99
|
-
columns: {
|
|
100
|
-
id: true,
|
|
101
|
-
name: true
|
|
102
|
-
},
|
|
103
|
-
orderBy: [asc(Role.name)]
|
|
104
|
-
})
|
|
105
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InferSelectModel,
|
|
3
|
-
asc,
|
|
4
|
-
count,
|
|
5
|
-
desc,
|
|
6
|
-
eq,
|
|
7
|
-
ilike,
|
|
8
|
-
or,
|
|
9
|
-
sql
|
|
10
|
-
} from 'drizzle-orm'
|
|
11
|
-
|
|
12
|
-
import { db } from '@/db'
|
|
13
|
-
import { Task } from '@/db/schema'
|
|
14
|
-
import { type SortOrderEnum } from '@/lib/sortOrderEnum'
|
|
15
|
-
|
|
16
|
-
export type TaskType = InferSelectModel<typeof Task>
|
|
17
|
-
|
|
18
|
-
type getTasksInput = {
|
|
19
|
-
page: number
|
|
20
|
-
limit: number
|
|
21
|
-
sortBy?: keyof TaskType
|
|
22
|
-
sortOrder?: SortOrderEnum
|
|
23
|
-
filters?: {
|
|
24
|
-
title?: string
|
|
25
|
-
status?: TaskType['status'][]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const getTasksWithUser = async ({
|
|
30
|
-
page,
|
|
31
|
-
limit,
|
|
32
|
-
sortBy,
|
|
33
|
-
sortOrder,
|
|
34
|
-
filters
|
|
35
|
-
}: getTasksInput) => {
|
|
36
|
-
const where = or(
|
|
37
|
-
filters?.title ? ilike(Task.title, `%${filters.title}%`) : undefined,
|
|
38
|
-
...(filters?.status || []).map(f => eq(Task.status, f))
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const [tasks, total] = await Promise.all([
|
|
42
|
-
db.query.Task.findMany({
|
|
43
|
-
columns: {
|
|
44
|
-
id: true,
|
|
45
|
-
title: true,
|
|
46
|
-
status: true,
|
|
47
|
-
createdAt: true,
|
|
48
|
-
updatedAt: true
|
|
49
|
-
},
|
|
50
|
-
with: {
|
|
51
|
-
createdBy: {
|
|
52
|
-
columns: {
|
|
53
|
-
id: true,
|
|
54
|
-
name: true
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
updatedBy: {
|
|
58
|
-
columns: {
|
|
59
|
-
id: true,
|
|
60
|
-
name: true
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
where,
|
|
65
|
-
orderBy: [
|
|
66
|
-
sortOrder === 'asc'
|
|
67
|
-
? asc(Task[sortBy || 'createdAt'])
|
|
68
|
-
: desc(Task[sortBy || 'createdAt'])
|
|
69
|
-
],
|
|
70
|
-
offset: (page - 1) * limit,
|
|
71
|
-
limit
|
|
72
|
-
}),
|
|
73
|
-
db
|
|
74
|
-
.select({
|
|
75
|
-
count: count()
|
|
76
|
-
})
|
|
77
|
-
.from(Task)
|
|
78
|
-
.where(where)
|
|
79
|
-
])
|
|
80
|
-
|
|
81
|
-
return { tasks, total: total[0]?.count || 0 }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const getTaskByIdWithUser = async (id: string) => {
|
|
85
|
-
return await db.query.Task.findFirst({
|
|
86
|
-
where: eq(Task.id, id),
|
|
87
|
-
with: {
|
|
88
|
-
createdBy: {
|
|
89
|
-
columns: {
|
|
90
|
-
id: true,
|
|
91
|
-
name: true
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
updatedBy: {
|
|
95
|
-
columns: {
|
|
96
|
-
id: true,
|
|
97
|
-
name: true
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
type createTaskInput = {
|
|
105
|
-
title: string
|
|
106
|
-
description?: string | null
|
|
107
|
-
status: TaskType['status']
|
|
108
|
-
createdById: string
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const createTask = async (data: createTaskInput) => {
|
|
112
|
-
const newTask = await db.insert(Task).values(data).returning({
|
|
113
|
-
id: Task.id
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
if (!newTask[0]?.id) throw new Error('Failed to create task')
|
|
117
|
-
|
|
118
|
-
return newTask[0].id
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
type updateTaskInput = {
|
|
122
|
-
id: string
|
|
123
|
-
title?: string
|
|
124
|
-
description?: string | null
|
|
125
|
-
status?: TaskType['status']
|
|
126
|
-
updatedById: string
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const updateTask = async (data: updateTaskInput) => {
|
|
130
|
-
return await db
|
|
131
|
-
.update(Task)
|
|
132
|
-
.set({
|
|
133
|
-
...data,
|
|
134
|
-
updatedAt: sql`now()`
|
|
135
|
-
})
|
|
136
|
-
.where(eq(Task.id, data.id))
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export const deleteTask = async (id: string) => {
|
|
140
|
-
return await db.delete(Task).where(eq(Task.id, id))
|
|
141
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InferSelectModel,
|
|
3
|
-
asc,
|
|
4
|
-
count,
|
|
5
|
-
desc,
|
|
6
|
-
eq,
|
|
7
|
-
ilike,
|
|
8
|
-
or,
|
|
9
|
-
sql
|
|
10
|
-
} from 'drizzle-orm'
|
|
11
|
-
|
|
12
|
-
import { db } from '@/db'
|
|
13
|
-
import { User } from '@/db/schema'
|
|
14
|
-
import { type SortOrderEnum } from '@/lib/sortOrderEnum'
|
|
15
|
-
|
|
16
|
-
export type UserType = InferSelectModel<typeof User>
|
|
17
|
-
|
|
18
|
-
type updateUserByIdInput = {
|
|
19
|
-
name?: string | null
|
|
20
|
-
type?: UserType['type']
|
|
21
|
-
roleId?: string | null
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const updateUser = async (id: string, data: updateUserByIdInput) => {
|
|
25
|
-
await db
|
|
26
|
-
.update(User)
|
|
27
|
-
.set({ ...data, updatedAt: sql`now()` })
|
|
28
|
-
.where(eq(User.id, id))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type getUsersInput = {
|
|
32
|
-
page: number
|
|
33
|
-
limit: number
|
|
34
|
-
sortBy?: keyof UserType
|
|
35
|
-
sortOrder?: SortOrderEnum
|
|
36
|
-
filters?: {
|
|
37
|
-
name?: string
|
|
38
|
-
email?: string
|
|
39
|
-
type?: UserType['type'][]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const getUsersWithRole = async ({
|
|
44
|
-
page,
|
|
45
|
-
limit,
|
|
46
|
-
sortBy,
|
|
47
|
-
sortOrder,
|
|
48
|
-
filters
|
|
49
|
-
}: getUsersInput) => {
|
|
50
|
-
const where = or(
|
|
51
|
-
filters?.name ? ilike(User.name, `%${filters.name}%`) : undefined,
|
|
52
|
-
filters?.email ? ilike(User.email, `%${filters.email}%`) : undefined,
|
|
53
|
-
...(filters?.type || []).map(f => eq(User.type, f))
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
const [users, total] = await Promise.all([
|
|
57
|
-
db.query.User.findMany({
|
|
58
|
-
columns: {
|
|
59
|
-
id: true,
|
|
60
|
-
name: true,
|
|
61
|
-
email: true,
|
|
62
|
-
type: true,
|
|
63
|
-
roleId: true,
|
|
64
|
-
image: true,
|
|
65
|
-
emailVerified: true,
|
|
66
|
-
createdAt: true,
|
|
67
|
-
updatedAt: true
|
|
68
|
-
},
|
|
69
|
-
with: {
|
|
70
|
-
role: true
|
|
71
|
-
},
|
|
72
|
-
where,
|
|
73
|
-
orderBy: [
|
|
74
|
-
sortOrder === 'asc'
|
|
75
|
-
? asc(User[sortBy || 'createdAt'])
|
|
76
|
-
: desc(User[sortBy || 'createdAt'])
|
|
77
|
-
],
|
|
78
|
-
offset: (page - 1) * limit,
|
|
79
|
-
limit
|
|
80
|
-
}),
|
|
81
|
-
db
|
|
82
|
-
.select({
|
|
83
|
-
count: count()
|
|
84
|
-
})
|
|
85
|
-
.from(User)
|
|
86
|
-
.where(where)
|
|
87
|
-
])
|
|
88
|
-
|
|
89
|
-
return { users, total: total[0]?.count || 0 }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const getUserById = async (id: string) => {
|
|
93
|
-
return await db.query.User.findFirst({
|
|
94
|
-
where: eq(User.id, id),
|
|
95
|
-
columns: {
|
|
96
|
-
id: true,
|
|
97
|
-
name: true,
|
|
98
|
-
email: true,
|
|
99
|
-
emailVerified: true,
|
|
100
|
-
type: true,
|
|
101
|
-
roleId: true,
|
|
102
|
-
createdAt: true,
|
|
103
|
-
updatedAt: true
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
type createUserInput = {
|
|
109
|
-
name?: string | null
|
|
110
|
-
email: string
|
|
111
|
-
type: UserType['type']
|
|
112
|
-
roleId?: string | null
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export const createUser = async ({
|
|
116
|
-
name,
|
|
117
|
-
email,
|
|
118
|
-
type,
|
|
119
|
-
roleId
|
|
120
|
-
}: createUserInput) => {
|
|
121
|
-
const newUser = await db
|
|
122
|
-
.insert(User)
|
|
123
|
-
.values({
|
|
124
|
-
name,
|
|
125
|
-
email,
|
|
126
|
-
type,
|
|
127
|
-
roleId
|
|
128
|
-
})
|
|
129
|
-
.returning({
|
|
130
|
-
id: User.id
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const id = newUser[0]?.id
|
|
134
|
-
if (!id) throw new Error('Failed to create user')
|
|
135
|
-
|
|
136
|
-
return id
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export const deleteUser = async (id: string) => {
|
|
140
|
-
return await db.delete(User).where(eq(User.id, id))
|
|
141
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { drizzle } from 'drizzle-orm/postgres-js'
|
|
2
|
-
import postgres from 'postgres'
|
|
3
|
-
|
|
4
|
-
import { env } from '@/env.mjs'
|
|
5
|
-
import * as schema from './schema'
|
|
6
|
-
|
|
7
|
-
const globalForDb = globalThis as unknown as {
|
|
8
|
-
conn: postgres.Sql | undefined
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const conn = globalForDb.conn ?? postgres(env.DATABASE_URL)
|
|
12
|
-
if (env.NODE_ENV !== 'production') globalForDb.conn = conn
|
|
13
|
-
|
|
14
|
-
export const db = drizzle(conn, { schema })
|