Skip to content

Commit

Permalink
Update +server.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
thejessewinton committed Aug 2, 2024
1 parent cbf1d94 commit a6b0134
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/routes/init/tickets/get-ticket-doc/+server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APPWRITE_COL_INIT_TWO_ID, APPWRITE_DB_INIT_ID } from '$env/static/private';
import { APPWRITE_DB_INIT_ID } from '$env/static/private';
import { env } from '$env/dynamic/private';
import { appwriteInitServer } from '$lib/appwrite/init.server';
import { isProUser } from '$lib/utils/console.js';
import type { User } from '$routes/init/helpers.js';
Expand Down Expand Up @@ -35,14 +36,14 @@ async function getTicketDocByUser(user: User) {
user.github?.login
? appwriteInitServer.databases.listDocuments(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
[Query.equal('gh_user', user.github.login)]
)
: null,
user.appwrite?.$id
? appwriteInitServer.databases.listDocuments(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
[Query.equal('aw_email', user.appwrite.email)]
)
: null,
Expand All @@ -59,7 +60,7 @@ async function getTicketDocByUser(user: User) {
const newest = gh_doc.id > aw_doc.id ? gh_doc.$id : aw_doc.$id;
await appwriteInitServer.databases.updateDocument(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
oldest,
{
gh_user: null,
Expand All @@ -68,7 +69,7 @@ async function getTicketDocByUser(user: User) {
);
return (await appwriteInitServer.databases.updateDocument(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
newest,
{
gh_user: user.github?.login,
Expand All @@ -83,7 +84,7 @@ async function getTicketDocByUser(user: User) {
if (!doc.gh_user || !doc.aw_email) {
return (await appwriteInitServer.databases.updateDocument(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
doc.$id,
{
gh_user: user.github?.login,
Expand All @@ -96,7 +97,7 @@ async function getTicketDocByUser(user: User) {
if (!!user.appwrite && doc.is_pro !== isPro) {
return (await appwriteInitServer.databases.updateDocument(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
doc.$id,
{
is_pro: isPro
Expand All @@ -110,11 +111,11 @@ async function getTicketDocByUser(user: User) {
// If no document exists, create one
const allDocs = await appwriteInitServer.databases.listDocuments(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID
env.APPWRITE_COL_INIT_TWO_ID
);
return (await appwriteInitServer.databases.createDocument(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
ID.unique(),
{
aw_email: user.appwrite?.email ?? undefined,
Expand All @@ -129,7 +130,7 @@ async function getTicketDocByUser(user: User) {
async function getTicketDocById(id: string) {
return (await appwriteInitServer.databases.getDocument(
APPWRITE_DB_INIT_ID,
APPWRITE_COL_INIT_TWO_ID,
env.APPWRITE_COL_INIT_TWO_ID,
id
)) as unknown as Omit<TicketData, 'contributions' | 'variant'>;
}
Expand Down

0 comments on commit a6b0134

Please sign in to comment.