Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: v2.0.0-beta cleaning #323

Merged
merged 10 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/lp/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export default defineNuxtConfig({
]
},

icon: {
clientBundle: {
scan: true,
includeCustomCollections: true
},
provider: 'iconify'
},

css: ['~/assets/style/main.css'],

colorMode: {
Expand Down
2 changes: 1 addition & 1 deletion apps/lp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@tsparticles/slim": "^3.6.0",
"@nuxt/image": "^1.8.1",
"@nuxt/scripts": "^0.9.5",
"@nuxt/ui": "https://pkg.pr.new/@nuxt/ui@25091ba",
"@nuxt/ui": "3.0.0-alpha.9",
"@nuxtjs/seo": "^2.0.0-rc.23",
"@iconify-json/heroicons": "^1.2.1",
"@iconify-json/lucide": "^1.2.15",
Expand Down
2 changes: 1 addition & 1 deletion apps/shelve/app/components/project/CreateVariables.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const handlePasswordGenerated = (password: string, index: number) => variablesIn
</h4>
<div class="flex select-none gap-4">
<UCheckbox v-model="selectedEnvironment.production" name="production" label="Production" />
<UCheckbox v-model="selectedEnvironment.preview" name="preview" label="Staging" />
<UCheckbox v-model="selectedEnvironment.preview" name="preview" label="Preview" />
<UCheckbox v-model="selectedEnvironment.development" name="development" label="Development" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/shelve/app/components/project/VariableItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const showEdit = ref(false)
</h4>
<div class="flex flex-col gap-4">
<UCheckbox v-model="selectedEnvironment.production" name="production" label="Production" />
<UCheckbox v-model="selectedEnvironment.preview" name="preview" label="Staging" />
<UCheckbox v-model="selectedEnvironment.preview" name="preview" label="Preview" />
<UCheckbox v-model="selectedEnvironment.development" name="development" label="Development" />
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions apps/shelve/app/composables/useProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const useUserProjects = () => {
}

export const useCurrentProject = () => {
return useState<Project>('currentProject')
return useState<Project | null>('currentProject', () => null)
}

export function useProjects() {
Expand Down Expand Up @@ -76,7 +76,6 @@ export function useProjects() {

return {
projects,
currentProject,
loading,
currentLoading,
fetchProjects,
Expand Down
2 changes: 2 additions & 0 deletions apps/shelve/app/composables/useTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export function useTeams() {
}

async function selectTeam(id: number) {
const route = useRoute()
currentTeam.value = teams.value.find(team => team.id === id) as Team
lastUsedTeamId.value = id
if (route.path.includes('/project/')) navigateTo('/')
await useProjects().fetchProjects()
}

Expand Down
2 changes: 2 additions & 0 deletions apps/shelve/app/composables/useVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export function useVariables(refresh: () => Promise<void>, projectId: string) {
variablesToCreate.value = 1
variablesInput.value = {
projectId: +projectId,
autoUppercase: autoUppercase.value,
environment: environment.value,
variables: [
{
index: 1,
Expand Down
2 changes: 1 addition & 1 deletion apps/shelve/app/pages/project/[projectId]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ definePageMeta({
})

const { projectId } = useRoute().params as { projectId: string }
const currentProject = useCurrentProject()

const {
currentProject,
currentLoading,
fetchCurrentProject
} = useProjects()
Expand Down
2 changes: 2 additions & 0 deletions apps/shelve/auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ declare module '#auth-utils' {
avatar: string
authType: AuthType
role: Role
createdAt: Date
updatedAt: Date
}

// eslint-disable-next-line
Expand Down
5 changes: 5 additions & 0 deletions apps/shelve/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export default defineNuxtConfig({
dir: './app/assets/icons'
},
],
clientBundle: {
scan: true,
includeCustomCollections: true
},
provider: 'iconify'
},

colorMode: {
Expand Down
3 changes: 2 additions & 1 deletion apps/shelve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"@iconify-json/simple-icons": "^1.2.12",
"@nuxt/devtools": "^1.6.0",
"@nuxt/image": "^1.8.1",
"@nuxt/ui": "https://pkg.pr.new/@nuxt/ui@25091ba",
"@nuxt/ui": "3.0.0-alpha.9",
"@shelve/crypto": "*",
"@shelve/utils": "*",
"drizzle-orm": "^0.36.3",
"pg": "^8.13.1",
"vue": "^3.5.13",
Expand Down
14 changes: 14 additions & 0 deletions apps/shelve/server/api/admin/users/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { zh } from 'h3-zod'
import { UserService } from '~~/server/services/user.service'
import { idParamsSchema } from '~~/server/database/zod'

export default eventHandler(async (event) => {
const { user } = await requireUserSession(event)
const { id } = await zh.useValidatedParams(event, idParamsSchema)
if (user.id === id) throw createError({ statusCode: 400, statusMessage: 'you can\'t delete your own account' })
await new UserService().deleteUserById(id)
return {
statusCode: 200,
message: 'user deleted',
}
})
21 changes: 21 additions & 0 deletions apps/shelve/server/api/admin/users/[id].put.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { zh, z } from 'h3-zod'
import { Role } from '@shelve/types'
import { idParamsSchema } from '~~/server/database/zod'

export default eventHandler(async (event) => {
const { user } = await requireUserSession(event)
const { id } = await zh.useValidatedParams(event, idParamsSchema)
const { role } = await zh.useValidatedBody(event, {
role: z.nativeEnum(Role),
})
if (user.id === id) throw createError({ statusCode: 400, statusMessage: 'you can\'t update your own role' })
await db.update(tables.users)
.set({
role
})
.where(eq(tables.users.id, id))
return {
statusCode: 200,
message: 'user updated',
}
})
17 changes: 0 additions & 17 deletions apps/shelve/server/api/admin/users/[userId].delete.ts

This file was deleted.

25 changes: 0 additions & 25 deletions apps/shelve/server/api/admin/users/[userId].put.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/shelve/server/api/auth/currentUser.get.ts

This file was deleted.

12 changes: 5 additions & 7 deletions apps/shelve/server/api/project/[id]/index.delete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { z, zh } from 'h3-zod'
import { zh } from 'h3-zod'
import { ProjectService } from '~~/server/services/project.service'
import { idParamsSchema } from '~~/server/database/zod'

export default eventHandler(async (event) => {
const { id } = await zh.useValidatedParams(event, {
id: z.string({
required_error: 'Project ID is required',
}).transform((value) => parseInt(value, 10)),
})
await new ProjectService().deleteProject(id, event.context.user.id)
const { user } = await requireUserSession(event)
const { id } = await zh.useValidatedParams(event, idParamsSchema)
await new ProjectService().deleteProject(id, user.id)
return {
statusCode: 200,
message: 'Project deleted',
Expand Down
12 changes: 5 additions & 7 deletions apps/shelve/server/api/project/[id]/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { z, zh } from 'h3-zod'
import { zh } from 'h3-zod'
import { ProjectService } from '~~/server/services/project.service'
import { idParamsSchema } from '~~/server/database/zod'

export default eventHandler(async (event) => {
const { id } = await zh.useValidatedParams(event, {
id: z.string({
required_error: 'Project ID is required',
}).transform((value) => parseInt(value, 10)),
})
return await new ProjectService().getProjectById(id, event.context.user.id)
const { user } = await requireUserSession(event)
const { id } = await zh.useValidatedParams(event, idParamsSchema)
return await new ProjectService().getProjectById(id, user.id)
})
17 changes: 6 additions & 11 deletions apps/shelve/server/api/project/[id]/index.put.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { z, zh } from 'h3-zod'
import type { ProjectUpdateInput } from '@shelve/types'
import { ProjectService } from '~~/server/services/project.service'
import { idParamsSchema } from '~~/server/database/zod'

export default eventHandler(async (event) => {
const { id } = await zh.useValidatedParams(event, {
id: z.string({
required_error: 'Project ID is required',
}).transform((value) => parseInt(value, 10)),
})
const { user } = await requireUserSession(event)
const { id } = await zh.useValidatedParams(event, idParamsSchema)
const body = await zh.useValidatedBody(event, {
name: z.string({
required_error: 'Project name is required',
Expand All @@ -22,9 +19,8 @@ export default eventHandler(async (event) => {
required_error: 'Team ID is required',
}).positive(),
})
const { user } = event.context
const input: ProjectUpdateInput = {
id: id,
return await new ProjectService().updateProject({
id,
name: body.name,
description: body.description,
homepage: body.homepage,
Expand All @@ -37,6 +33,5 @@ export default eventHandler(async (event) => {
id: user.id,
role: user.role,
}
}
return await new ProjectService().updateProject(input)
})
})
8 changes: 3 additions & 5 deletions apps/shelve/server/api/project/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z, zh } from 'h3-zod'
import type { CreateProjectInput } from '@shelve/types'
import { ProjectService } from '~~/server/services/project.service'

export default eventHandler(async (event) => {
const { user } = await requireUserSession(event)
const body = await zh.useValidatedBody(event, {
name: z.string({
required_error: 'Name is required',
Expand All @@ -17,13 +17,11 @@ export default eventHandler(async (event) => {
homepage: z.string().trim().optional(),
variablePrefix: z.string().trim().optional(),
})
const { user } = event.context
const input: CreateProjectInput = {
return await new ProjectService().createProject({
...body,
requester: {
id: user.id,
role: user.role,
}
}
return await new ProjectService().createProject(input)
})
})
4 changes: 2 additions & 2 deletions apps/shelve/server/api/project/name/[name].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export default eventHandler(async (event) => {
.transform((value) => decodeURIComponent(value)),
})
let { teamId } = await zh.useValidatedQuery(event, {
teamId: z.string().transform((value) => parseInt(value, 10)),
teamId: z.coerce.number().optional(),
})

if (!teamId) teamId = (await new TeamService().getPrivateUserTeam(user.id)).id
if (!teamId) teamId = await new TeamService().getPrivateUserTeamId(user.id)

const project = await db.query.projects.findFirst({
where: and(ilike(tables.projects.name, name), eq(tables.projects.teamId, teamId)),
Expand Down
18 changes: 8 additions & 10 deletions apps/shelve/server/api/teams/[teamId]/index.delete.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { z, zh } from 'h3-zod'
import type { DeleteTeamInput } from '@shelve/types'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler(async (event) => {
const { user } = event.context
const params = await zh.useValidatedParams(event, {
teamId: z.string({
required_error: 'Missing teamId',
}).transform((value) => parseInt(value)),
const { user } = await requireUserSession(event)
const { teamId } = await zh.useValidatedParams(event, {
teamId: z.coerce.number({
required_error: 'Missing team ID',
}),
})
const input = {
teamId: params.teamId,
await new TeamService().deleteTeam({
teamId,
requester: {
id: user.id,
role: user.role,
}
} as DeleteTeamInput
await new TeamService().deleteTeam(input)
})
return {
statusCode: 200,
message: 'Team deleted',
Expand Down
8 changes: 4 additions & 4 deletions apps/shelve/server/api/teams/[teamId]/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { z, zh } from 'h3-zod'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler(async (event) => {
const { user } = await requireUserSession(event)
const { teamId } = await zh.useValidatedParams(event, {
teamId: z.string({
required_error: 'Missing teamId',
}).transform((value) => parseInt(value)),
teamId: z.coerce.number({
required_error: 'Missing team ID',
}),
})
const { user } = event.context
return await new TeamService().getTeamById(teamId, {
id: user.id,
role: user.role,
Expand Down
Loading