Skip to content

Commit 4cfb946

Browse files
authored
Merge pull request #42 from coderKrysio/dev-1
updated types
2 parents afe6b9f + 7aff12e commit 4cfb946

File tree

6 files changed

+27
-33
lines changed

6 files changed

+27
-33
lines changed

app/api/[roomcode]/delete/route.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1+
import { RoomCodeRouteContext } from '@/lib/types'
12
import clientPromise from '@/utils/newdb'
23

3-
type RoomCodeRouteContext = {
4-
params: {
5-
roomcode: string
6-
}
7-
}
8-
9-
export async function DELETE(request: Request, context: RoomCodeRouteContext) {
4+
export async function DELETE(_request: Request, context: RoomCodeRouteContext) {
105
try {
116
const client = await clientPromise
127
const db = client.db('get_interval')
@@ -25,7 +20,7 @@ export async function DELETE(request: Request, context: RoomCodeRouteContext) {
2520
roomcode: context.params.roomcode,
2621
})
2722

28-
return new Response('Deleted Successfully!!', { status: 200 })
23+
return new Response(JSON.stringify(''), { status: 200 })
2924
} catch (error) {
3025
console.log(error)
3126
return new Response('Failed to delete, Try again later!!', {

app/api/[roomcode]/review/route.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1+
import { RoomCodeRouteContext } from '@/lib/types'
12
import clientPromise from '@/utils/newdb'
23

3-
type RoomCodeRouteContext = {
4-
params: {
5-
roomcode: string
6-
}
7-
}
8-
9-
export async function GET(request: Request, context: RoomCodeRouteContext) {
4+
export async function GET(_request: Request, context: RoomCodeRouteContext) {
105
try {
116
const client = await clientPromise
127
const db = client.db('get_interval')
@@ -17,7 +12,7 @@ export async function GET(request: Request, context: RoomCodeRouteContext) {
1712
.limit(15)
1813
.toArray()
1914
if (rooms.length === 0) {
20-
return new Response('Oops, No data!', { status: 200 })
15+
return new Response('Oops, No data!', { status: 400 })
2116
}
2217

2318
return new Response(JSON.stringify(rooms), { status: 200 })

app/api/[roomcode]/route.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1+
import { RoomCodeRouteContext } from '@/lib/types'
12
import clientPromise from '@/utils/newdb'
23

3-
type RoomCodeRouteContext = {
4-
params: {
5-
roomcode: string
6-
}
7-
}
8-
9-
export async function GET(request: Request, context: RoomCodeRouteContext) {
4+
export async function GET(_request: Request, context: RoomCodeRouteContext) {
105
try {
116
const client = await clientPromise
127
const db = client.db('get_interval')
@@ -25,7 +20,7 @@ export async function GET(request: Request, context: RoomCodeRouteContext) {
2520
.limit(15)
2621
.toArray()
2722

28-
console.log(rooms)
23+
// console.log(rooms)
2924

3025
//to get all the intervals in a single array
3126
let intervals: any[] = [[]]
@@ -91,7 +86,7 @@ export async function GET(request: Request, context: RoomCodeRouteContext) {
9186
console.log('Saved Successfully!')
9287
} else {
9388
result = await results[0].result
94-
console.log(result)
89+
// console.log(result)
9590
}
9691

9792
return new Response(JSON.stringify(result), { status: 200 })

app/api/new-room/route.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Room from '@/models/room'
1+
import { SetUser } from '@/lib/types'
22
import clientPromise from '@/utils/newdb'
33

44
export async function POST(request: Request) {
5-
const { username, roomcode, timeRanges } = await request.json()
5+
const { username, roomcode, timeRanges }: SetUser = await request.json()
66
try {
77
const client = await clientPromise
88
const db = client.db('get_interval')
@@ -15,8 +15,7 @@ export async function POST(request: Request) {
1515
timeRanges: timeRanges,
1616
})
1717

18-
console.log('New Room Created!')
19-
return new Response('Success!', { status: 200 })
18+
return new Response(JSON.stringify(roomcode), { status: 200 })
2019
} catch (error) {
2120
console.log(error)
2221
return new Response('Failed to create a new room, try again later!', {

components/GetForm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SetStateAction, useState } from 'react'
1+
import { useState } from 'react'
22
import Navbar from './Navbar'
33
import { svgSrc, timeIntervals } from '@/lib/utils'
44
import Link from 'next/link'
@@ -19,12 +19,10 @@ const GetForm = ({ roomCode }: RoomCode) => {
1919
if (formData.name === '') setShowError(true)
2020
else {
2121
setShowError(false)
22-
router.push(`/${roomCode}/result`)
22+
//router.push(`/${roomCode}/result`)
2323
}
2424
}
2525

26-
console.log(formData)
27-
2826
return (
2927
<div className="w-screen min-h-screen flex flex-col justify-center items-center text-white pb-[70px] pt-[90px]">
3028
<Navbar />

lib/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { Dispatch, SetStateAction } from "react"
22

3+
export interface SetUser {
4+
username: string,
5+
roomcode: string,
6+
timeRanges: number[][]
7+
}
8+
9+
export type RoomCodeRouteContext = {
10+
params: {
11+
roomcode: string
12+
}
13+
}
14+
315
export interface RoomCode {
416
roomCode: string
517
}

0 commit comments

Comments
 (0)