Skip to content

Commit

Permalink
enhancement: Refactor server functions and files for better maintaina…
Browse files Browse the repository at this point in the history
…bility (#264)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
HugoRCD and autofix-ci[bot] authored Nov 1, 2024
1 parent 8a08891 commit 86d6091
Show file tree
Hide file tree
Showing 78 changed files with 1,542 additions and 1,177 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "🐛 Bug report"
description: Report a bug to help us improve the project.
labels: ["bug"]
title: "fix: "
body:
- type: markdown
attributes:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/enhancement-request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "🌈 Enhancement request"
description: Suggest an idea or enhancement for the project.
labels: ["enhancement"]
title: "enhancement: "
body:
- type: markdown
attributes:
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "🚀 Feature request"
description: Suggest an idea or enhancement for the project.
labels: ["enhancement"]
labels: ["feature"]
title: "feat: "
body:
- type: markdown
attributes:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ permissions:
jobs:
autofix:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/continuous-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- name: Checkout code
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ dist
.idea

.config/shelve*

*/dist/
*/.output/
2 changes: 1 addition & 1 deletion apps/shelve/.config/shelve.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/HugoRCD/shelve/main/packages/types/shelveConfigSchema.json",
"project": "shelve"
}
}
1 change: 0 additions & 1 deletion apps/shelve/app/components/OTP.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const digits = reactive<[string | null]>([null])
const otp = defineModel({ type: String })
for (let i = 0; i < props.digitCount; i++) {
// eslint-disable-next-line vue/no-ref-object-reactivity-loss
digits[i] = otp.value![i] || null
}
Expand Down
4 changes: 2 additions & 2 deletions apps/shelve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"@nuxtjs/seo": "^2.0.0-rc.23",
"@prisma/client": "^5.21.1",
"@shelve/cli": "^2.4.0",
"@shelve/crypto": "workspace:*",
"@shelve/types": "workspace:*",
"@shelve/crypto": "*",
"@shelve/types": "*",
"@tsparticles/engine": "^3.5.0",
"@tsparticles/slim": "^3.5.0",
"@vitejs/plugin-vue": "^5.1.4",
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/admin/users/[userId].delete.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { H3Event } from 'h3'
import { deleteUser } from '~~/server/app/userService'
import type { H3Event } from 'h3'
import { UserService } from '~~/server/services/user.service'

export default eventHandler(async (event: H3Event) => {
const userService = new UserService()
const { user } = event.context
const id = getRouterParam(event, 'userId') as string
if (!id) throw createError({ statusCode: 400, statusMessage: 'missing params' })
if (user.id === parseInt(id)) throw createError({ statusCode: 400, statusMessage: 'you can\'t delete your own account' })
await deleteUser(parseInt(id))
await userService.deleteUser(parseInt(id))
return {
statusCode: 200,
message: 'user deleted',
Expand Down
2 changes: 1 addition & 1 deletion apps/shelve/server/api/admin/users/[userId].put.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { H3Event } from 'h3'
import type { H3Event } from 'h3'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/auth/currentUser.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { H3Event } from 'h3'
import { getUserByAuthToken } from '~~/server/app/tokenService'
import type { H3Event } from 'h3'
import { TokenService } from '~~/server/services/token.service'

export default eventHandler(async (event: H3Event) => {
const tokenService = new TokenService()
const authToken = getCookie(event, 'authToken') || ''

return await getUserByAuthToken(authToken)
return await tokenService.getUserByAuthToken(authToken)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/github/repos.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { H3Event } from 'h3'
import { getUserRepos } from '~~/server/app/githubService'
import type { H3Event } from 'h3'
import { GitHubService } from '~~/server/services/github.service'

export default defineEventHandler(async (event: H3Event) => {
return await getUserRepos(event)
const githubService = new GitHubService()
return await githubService.getUserRepos(event)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/github/upload.post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { H3Event } from 'h3'
import { uploadFile } from '~~/server/app/githubService'
import type { H3Event } from 'h3'
import { GitHubService } from '~~/server/services/github.service'

export default defineEventHandler(async (event: H3Event) => {
const formData = await readMultipartFormData(event)
Expand All @@ -17,9 +17,10 @@ export default defineEventHandler(async (event: H3Event) => {
statusMessage: 'No file provided'
})
}
const gitHubService = new GitHubService()

const file = new File([fileField.data], fileField.filename, { type: fileField.type })
const repoName = 'astra'

return await uploadFile(event, file, repoName)
return await gitHubService.uploadFile(event, file, repoName)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/[id]/index.delete.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { H3Event } from 'h3'
import { deleteProject } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
const id = getRouterParam(event, 'id') as string
if (!id) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
await deleteProject(id, user.id)
const projectService = new ProjectService()
await projectService.deleteProject(id, user.id)
return {
statusCode: 200,
message: 'Project deleted',
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/[id]/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { H3Event } from 'h3'
import { getProjectById } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default eventHandler(async (event: H3Event) => {
const id = getRouterParam(event, 'id') as string
if (!id) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
return await getProjectById(parseInt(id))
const projectService = new ProjectService()
return await projectService.getProjectById(+id)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/[id]/index.put.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { H3Event } from 'h3'
import { updateProject } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
const id = getRouterParam(event, 'id') as string
if (!id) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
const projectService = new ProjectService()
const projectUpdateInput = await readBody(event)
delete projectUpdateInput.variables
delete projectUpdateInput.team
projectUpdateInput.name = projectUpdateInput.name.trim()
return await updateProject(projectUpdateInput, parseInt(id), user.id)
return await projectService.updateProject(projectUpdateInput, +id, user.id)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/[id]/team/[teamId].delete.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { H3Event } from 'h3'
import { removeTeamFromProject } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default defineEventHandler(async (event: H3Event) => {
const id = getRouterParam(event, 'id') as string
const teamId = getRouterParam(event, 'teamId') as string
if (!id || !teamId) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
await removeTeamFromProject(+id, +teamId)
const projectService = new ProjectService()
await projectService.removeTeamFromProject(+id, +teamId)
return {
statusCode: 200,
message: 'Team removed from project',
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/[id]/team/[teamId].post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { H3Event } from 'h3'
import { addTeamToProject } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default defineEventHandler(async (event: H3Event) => {
const id = getRouterParam(event, 'id') as string
const teamId = getRouterParam(event, 'teamId') as string
if (!id || !teamId) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
await addTeamToProject(+id, +teamId)
const projectService = new ProjectService()
await projectService.addTeamToProject(+id, +teamId)
return {
statusCode: 200,
message: 'Team added to project',
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { H3Event } from 'h3'
import { getProjectsByUserId } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default eventHandler(async (event: H3Event) => {
const projectService = new ProjectService()
const { user } = event.context
if (!user) throw createError({ statusCode: 401, message: 'Unauthorized' })
return await getProjectsByUserId(user.id)
return await projectService.getProjectsByUserId(user.id)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/project/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { H3Event } from 'h3'
import { createProject } from '~~/server/app/projectService'
import type { H3Event } from 'h3'
import { ProjectService } from '~~/server/services/project.service'

export default eventHandler(async (event: H3Event) => {
const projectService = new ProjectService()
const { user } = event.context
const projectCreateInput = await readBody(event)
delete projectCreateInput.variables
projectCreateInput.name = projectCreateInput.name.trim()
return await createProject(projectCreateInput, user.id)
return await projectService.createProject(projectCreateInput, user.id)
})
3 changes: 1 addition & 2 deletions apps/shelve/server/api/project/name/[name].get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { H3Event } from 'h3'

import type { H3Event } from 'h3'

export default eventHandler(async (event: H3Event) => {
const paramName = getRouterParam(event, 'name')
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/teams/[teamId]/index.delete.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { H3Event } from 'h3'
import { deleteTeam } from '~~/server/app/teamsService'
import type { H3Event } from 'h3'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
const id = getRouterParam(event, 'teamId') as string
if (!id) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
await deleteTeam({
const teamService = new TeamService()
await teamService.deleteTeam({
teamId: parseInt(id),
userId: user.id,
userRole: user.role,
Expand Down
16 changes: 0 additions & 16 deletions apps/shelve/server/api/teams/[teamId]/index.put.ts

This file was deleted.

7 changes: 4 additions & 3 deletions apps/shelve/server/api/teams/[teamId]/members/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { H3Event } from 'h3'
import { removeMember } from '~~/server/app/teamsService'
import type { H3Event } from 'h3'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
const teamId = getRouterParam(event, 'teamId') as string
const memberId = getRouterParam(event, 'id') as string
if (!teamId || !memberId) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
await removeMember(parseInt(teamId), parseInt(memberId), user.id)
const teamService = new TeamService()
await teamService.removeMember(+teamId, +memberId, user.id)
return {
statusCode: 200,
message: 'Member removed',
Expand Down
7 changes: 4 additions & 3 deletions apps/shelve/server/api/teams/[teamId]/members/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { H3Event } from 'h3'
import { upsertMember } from '~~/server/app/teamsService'
import type { H3Event } from 'h3'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
const teamId = getRouterParam(event, 'teamId') as string
if (!teamId) throw createError({ statusCode: 400, statusMessage: 'Missing params' })
const teamService = new TeamService()
const addMemberInput = await readBody(event)
return await upsertMember(parseInt(teamId), addMemberInput, user.id)
return await teamService.upsertMember(+teamId, addMemberInput, user.id)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/teams/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { H3Event } from 'h3'
import { getTeamByUserId } from '~~/server/app/teamsService'
import type { H3Event } from 'h3'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler((event: H3Event) => {
const teamService = new TeamService()
const { user } = event.context
return getTeamByUserId(user.id)
return teamService.getTeamByUserId(user.id)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/teams/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { H3Event } from 'h3'
import type { H3Event } from 'h3'
import type { CreateTeamInput } from '@shelve/types'
import { createTeam } from '~~/server/app/teamsService'
import { TeamService } from '~~/server/services/teams.service'

export default eventHandler(async (event: H3Event) => {
const { user } = event.context
const createTeamInput = await readBody(event) as CreateTeamInput
if (!createTeamInput.name) throw createError({ statusCode: 400, statusMessage: 'Cannot create team without name' })
const teamService = new TeamService()
createTeamInput.name = createTeamInput.name.trim()
return await createTeam(createTeamInput, user.id)
return await teamService.createTeam(createTeamInput, user.id)
})
12 changes: 4 additions & 8 deletions apps/shelve/server/api/tokens/[id].delete.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { H3Event } from 'h3'

import type { H3Event } from 'h3'
import { TokenService } from '~~/server/services/token.service'

export default defineEventHandler(async (event: H3Event) => {
const tokenService = new TokenService()
const { user } = event.context
const id = getRouterParam(event, 'id') as string

if (!id) throw createError({ statusCode: 400, statusMessage: 'Missing params' })

await prisma.token.delete({
where: {
id: +id,
userId: user.id,
},
})
await tokenService.deleteUserToken(+id, user.id)
})
7 changes: 4 additions & 3 deletions apps/shelve/server/api/tokens/[token].get.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { H3Event } from 'h3'
import { getUserByAuthToken } from '~~/server/app/tokenService'
import type { H3Event } from 'h3'
import { TokenService } from '~~/server/services/token.service'

export default defineEventHandler((event: H3Event) => {
const tokenService = new TokenService()
const token = getRouterParam(event, 'token') as string
if (!token) throw createError({ statusCode: 400, statusMessage: 'Missing params' })

return getUserByAuthToken(token)
return tokenService.getUserByAuthToken(token)
})
Loading

0 comments on commit 86d6091

Please sign in to comment.