File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ export async function getWorkBookByUrlSlug(urlSlug: string): Promise<WorkBook |
6464// See:
6565// https://www.prisma.io/docs/orm/prisma-schema/data-model/relations#create-a-record-and-nested-records
6666export async function createWorkBook ( workBook : WorkBook ) : Promise < void > {
67+ const slug = workBook . urlSlug as string ;
68+
69+ if ( await isExistingUrlSlug ( slug ) ) {
70+ throw new Error ( `WorkBook slug ${ slug } has already existed` ) ;
71+ }
72+
6773 const sanitizedUrl = sanitizeUrl ( workBook . editorialUrl ) ;
6874 const newWorkBookTasks : WorkBookTasksBase = await getWorkBookTasks ( workBook ) ;
6975
@@ -90,6 +96,10 @@ export async function createWorkBook(workBook: WorkBook): Promise<void> {
9096 console . log ( `Created workbook with title: ${ newWorkBook . title } ` ) ;
9197}
9298
99+ async function isExistingUrlSlug ( slug : string ) : Promise < boolean > {
100+ return ( await getWorkBookByUrlSlug ( slug ) ) ? true : false ;
101+ }
102+
93103async function isExistingWorkBook ( workBookId : number ) : Promise < boolean > {
94104 const workBook = await getWorkBook ( workBookId ) ;
95105
You can’t perform that action at this time.
0 commit comments