-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-service.ts
More file actions
48 lines (41 loc) · 1.35 KB
/
project-service.ts
File metadata and controls
48 lines (41 loc) · 1.35 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
import type { CreateProjectFormSchema } from '$components/container/projects/create-project-schema'
import { createSlug } from 'shared/utils/slug/slug-service'
import { CreateProjectNameNotUniqueError } from '../error'
import * as repository from './project-repository'
import { SqliteError } from 'better-sqlite3'
export async function createProject(project: CreateProjectFormSchema) {
try {
const slug = createSlug(project.name)
return await repository.createProject({ ...project, slug })
} catch (e: unknown) {
if (e instanceof SqliteError && e.code === 'SQLITE_CONSTRAINT_UNIQUE') {
throw new CreateProjectNameNotUniqueError()
}
throw new Error('Error Creating Project')
}
}
export async function getAllProjects() {
try {
return await repository.getAllProjects()
} catch (e: unknown) {
throw new Error('Error Getting Projects')
}
}
export async function getProjectBySlug(slug: string) {
return await repository.getProjectBySlug(slug)
}
export async function checkProjectNameExists(name: string) {
try {
return await repository.checkProjectNameExists(name)
} catch (e) {
console.error(e)
throw new Error('Error Checking Project Name')
}
}
export async function checkProjectSlugExists(name: string) {
try {
return await repository.checkProjectSlugExists(createSlug(name))
} catch (e) {
throw new Error('Error Checking Project Slug')
}
}