-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from assistants-hub/93_store
Toggle for Public / Private assistants and visibility
- Loading branch information
Showing
13 changed files
with
274 additions
and
99 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240622051714_adding_the_published_flag/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Assistant" ADD COLUMN "published" BOOLEAN DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import prisma from '@/app/api/utils/prisma'; | ||
import { getSession } from '@auth0/nextjs-auth0'; | ||
|
||
const getId = (req: Request) => { | ||
const url = new URL(req.url); | ||
return url.pathname.split('/').splice(-2, 1)[0]; | ||
}; | ||
|
||
export async function PUT(req: NextRequest, res: NextResponse) { | ||
const session = await getSession(); | ||
const id = getId(req); | ||
|
||
try { | ||
if (session?.user) { | ||
let organization = await prisma.organization.findFirst({ | ||
where: { | ||
owner: session?.user.sub, | ||
ownerType: 'personal', | ||
}, | ||
}); | ||
|
||
if (organization) { | ||
let assistant = await prisma.assistant.findFirst({ | ||
where: { | ||
id: id, | ||
}, | ||
select: { | ||
id: true, | ||
organization: true, | ||
published: true, | ||
}, | ||
}); | ||
|
||
// @ts-ignore | ||
if (!assistant || assistant.organization.id !== organization.id) { | ||
return NextResponse.json({ message: 'Unauthorized' }, { | ||
status: 401, | ||
} as any); | ||
} else { | ||
await prisma.assistant.update({ | ||
where: { | ||
id: assistant.id, | ||
}, | ||
data: { | ||
// @ts-ignore | ||
published: !assistant.published, | ||
}, | ||
}); | ||
return NextResponse.json( | ||
{ message: 'Update successful' }, | ||
{ status: 200 } | ||
); | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
return NextResponse.json({ message: (error as Error).message }, { | ||
status: 400, | ||
} as any); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.