-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create calendar view in user profile
- Loading branch information
Showing
35 changed files
with
3,163 additions
and
456 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
import { ElysiaApp } from '@/app' | ||
import { db } from '@/utils/db' | ||
import { eq } from 'drizzle-orm' | ||
import { meetings, sessions, users } from '@/db/schema' | ||
import { t } from 'elysia' | ||
import { v4 as uuid } from 'uuid' | ||
import { validateRequest } from '@/utils/validateRequest' | ||
|
||
export default (app: ElysiaApp) => | ||
app | ||
.get('/', async ({ set, cookie: { auth_session } }) => { | ||
const userSession = await db.query.sessions.findFirst({ where: eq(sessions.id, auth_session.value) }) | ||
const { user, session } = await validateRequest(auth_session) | ||
|
||
if (user && session && userSession) { | ||
const userData = await db.query.users.findFirst({ where: eq(users.id, userSession.userId) }) | ||
|
||
if (userData?.accessToken) { | ||
const data = await db.select().from(meetings) | ||
set.status = 200 | ||
return data | ||
} | ||
|
||
if (!userData) { | ||
set.status = 401 | ||
return { message: 'unauthorized' } | ||
} | ||
} else { | ||
set.status = 401 | ||
return { message: 'unauthorized' } | ||
} | ||
}) | ||
.post( | ||
'/', | ||
async ({ set, body: { userId, trainerID, startTime, endTime }, cookie: { auth_session } }) => { | ||
const userSession = await db.query.sessions.findFirst({ where: eq(sessions.id, auth_session.value) }) | ||
|
||
if (userSession) { | ||
const userData = await db.query.users.findFirst({ where: eq(users.id, userSession.userId) }) | ||
|
||
if (userData?.accessToken) { | ||
const id = uuid() | ||
type NewMeeting = typeof meetings.$inferInsert | ||
const newMeeting: NewMeeting = { id, userId, trainerID, startTime, endTime } | ||
const meetingID = await db.insert(meetings).values(newMeeting).returning({ id: meetings.id }) | ||
|
||
set.status = 200 | ||
return meetingID | ||
} | ||
|
||
if (!userData) { | ||
set.status = 401 | ||
return { message: 'unauthorized' } | ||
} | ||
} else { | ||
set.status = 401 | ||
return { message: 'unauthorized' } | ||
} | ||
}, | ||
{ | ||
body: t.Object({ | ||
userId: t.String(), | ||
trainerID: t.String(), | ||
startTime: t.Date(), | ||
endTime: t.Date(), | ||
}), | ||
}, | ||
) |
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,35 @@ | ||
import { ElysiaApp } from '@/app' | ||
import { db } from '@/utils/db' | ||
import { eq } from 'drizzle-orm' | ||
import { sessions, trainers, users } from '@/db/schema' | ||
import { validateRequest } from '@/utils/validateRequest' | ||
|
||
export default (app: ElysiaApp) => | ||
app.get('/', async ({ set, cookie: { auth_session } }) => { | ||
const userSession = await db.query.sessions.findFirst({ where: eq(sessions.id, auth_session.value) }) | ||
const { user, session } = await validateRequest(auth_session) | ||
|
||
if (user && session && userSession) { | ||
const userData = await db.query.users.findFirst({ where: eq(users.id, userSession.userId) }) | ||
|
||
if (userData?.accessToken) { | ||
const data = await db.select({ | ||
id: trainers.id, | ||
name: trainers.name, | ||
username: trainers.username, | ||
email: trainers.email, | ||
profilePicture: trainers.profilePictureUrl, | ||
}).from(trainers) | ||
set.status = 200 | ||
return data | ||
} | ||
|
||
if (!userData) { | ||
set.status = 401 | ||
return { message: 'unauthorized' } | ||
} | ||
} else { | ||
set.status = 401 | ||
return { message: 'unauthorized' } | ||
} | ||
}) |
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.