Skip to content

Commit

Permalink
Merge pull request #220 from CS3219-AY2425S1/219-final-bug-fix
Browse files Browse the repository at this point in the history
Final bug fixes
  • Loading branch information
yunruu authored Nov 13, 2024
2 parents 714b694 + 0e9afb4 commit d49d36d
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class WebSocketConnection {

socket.on('end-session', async () => {
const socketsInRoom = this.io.sockets.adapter.rooms.get(roomId)
this.io.to(roomId).emit('session-ended')
if (socketsInRoom) {
socketsInRoom.forEach((socketId) => {
const socket = this.io.sockets.sockets.get(socketId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import logger from '../common/logger.util'
import {
createMatch,
findCompletedQuestionCount,
findMatchCount,
findMatchCountByUserId,
findOngoingMatch,
findPaginatedMatches,
findPaginatedMatchesWithSort,
Expand Down Expand Up @@ -165,7 +165,7 @@ export async function handleGetPaginatedSessions(request: IPaginationRequest, re
response.status(400).json('INVALID_SORT').send()
return
}
const count = await findMatchCount()
const count = await findMatchCountByUserId(userId)
let matches: IMatch[]

if (sortBy.length) {
Expand Down
6 changes: 4 additions & 2 deletions backend/matching-service/src/models/matching.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export function isValidSort(key: string, order: string): boolean {
return orders.includes(order) && keys.includes(key)
}

export async function findMatchCount(): Promise<number> {
return matchModel.countDocuments()
export async function findMatchCountByUserId(userId: string): Promise<number> {
return matchModel.countDocuments({
$or: [{ user1Id: userId }, { user2Id: userId }],
})
}

export async function findOngoingMatch(userId: string): Promise<IMatch> {
Expand Down
6 changes: 5 additions & 1 deletion frontend/components/account/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ function Setting() {
setIsFormSubmit(true)
toggleUpdateDialogOpen(false)
update({ ...session, user: response })
toast.success('Profile has been updated successfully.')
toast.success('Profile has been updated successfully. You will be signed out.')
setFormValues({ ...initialFormValues, email: defaultEmail })
setTimeout(async () => {
await signOut({ callbackUrl: '/auth' })
}, 1000)
} catch (error) {
if (error instanceof Error) {
toast.error(error.message)
Expand Down Expand Up @@ -92,6 +95,7 @@ function Setting() {
value={formValues.email}
onChange={handleFormChange}
error={formErrors.email}
isDisabled={true}
/>

<InputField
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/auth/PasswordReset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function PasswordReset() {
className="w-full py-3 px-3 border bg-[#EFEFEF] rounded-[5px]"
/>
<DialogFooter>
<Button type="submit" className="bg-purple-600 hover:bg-[#A78BFA]" onClick={onEnterEmail}>
<Button type="submit" variant="primary" onClick={onEnterEmail}>
Send Email
</Button>
</DialogFooter>
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/customs/custom-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface InputFieldProps {
className?: string
page?: string
handleKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void
isDisabled?: boolean
}

interface OptionsFieldProps {
Expand All @@ -39,6 +40,7 @@ export const InputField = (props: InputFieldProps): JSX.Element => {
placeholder={props.placeholder}
value={props.value}
onChange={props.onChange}
disabled={props.isDisabled}
className={
props.className
? props.className
Expand Down
7 changes: 6 additions & 1 deletion frontend/pages/code/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ export default function Code() {
})

socketRef.current.on('disconnect', () => {
if (!isViewOnly) {
router.push('/')
}
})

socketRef.current.on('session-ended', () => {
if (!isViewOnly) {
router.push('/')
toast.info('The session has ended')
Expand Down Expand Up @@ -197,7 +203,6 @@ export default function Code() {
function handleEndSessionConfirmation() {
if (socketRef.current) {
socketRef.current.emit('end-session')
router.push('/')
}
setIsDialogOpen(false)
}
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/sessions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function Sessions() {
})

const handleConfirmSessionOver = () => {
loadData()
setDialog((prev) => ({ ...prev, dialogData: { ...prev.dialogData, isOpen: false } }))
setOngoingSession('')
}
Expand Down
18 changes: 12 additions & 6 deletions frontend/services/question-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const getQuestionsRequest = async (data: IGetQuestions): Promise<IQuestio
return response
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error('An unexpected error occurred: ' + error.message)
const errMsg = error?.response?.data || 'INTERNAL SERVER ERROR'
throw new Error('An unexpected error occurred: ' + errMsg)
} else {
throw new Error('An unexpected error occurred')
}
Expand All @@ -47,12 +48,13 @@ export const getQuestionbyIDRequest = async (id: string): Promise<IQuestion | un
} catch (error) {
if (axios.isAxiosError(error)) {
const statusCode = error.response?.status
const errMsg = error?.response?.data || 'INTERNAL SERVER ERROR'

switch (statusCode) {
case 404:
throw new Error('Error getting questions: No such user!')
default:
throw new Error('An error occurred: ' + error.message)
throw new Error('An error occurred: ' + errMsg)
}
} else {
throw new Error('An unexpected error occurred')
Expand All @@ -77,6 +79,7 @@ export const createQuestionRequest = async (data: IQuestion): Promise<IQuestion
} catch (error) {
if (axios.isAxiosError(error)) {
const statusCode = error.response?.status
const errMsg = error?.response?.data || 'INTERNAL SERVER ERROR'

switch (statusCode) {
case 404:
Expand All @@ -89,7 +92,7 @@ export const createQuestionRequest = async (data: IQuestion): Promise<IQuestion
error.response?.data.map((err: string) => `(${err})`).join(', ')
)
default:
throw new Error('An unexpected error occurred: ' + error.message)
throw new Error('An unexpected error occurred: ' + errMsg)
}
} else {
throw new Error('An unexpected error occurred')
Expand All @@ -111,6 +114,7 @@ export const updateQuestionRequest = async (data: IQuestion): Promise<IQuestion
} catch (error) {
if (axios.isAxiosError(error)) {
const statusCode = error.response?.status
const errMsg = error?.response?.data || 'INTERNAL SERVER ERROR'

switch (statusCode) {
case 401:
Expand All @@ -123,7 +127,7 @@ export const updateQuestionRequest = async (data: IQuestion): Promise<IQuestion
error.response?.data.map((err: string) => `(${err})`).join(', ')
)
default:
throw new Error('An unexpected error occurred: ' + error.message)
throw new Error('An unexpected error occurred: ' + errMsg)
}
} else {
throw new Error('An unexpected error occurred')
Expand All @@ -139,14 +143,15 @@ export const deleteQuestionById = async (id: string): Promise<IQuestion | undefi
} catch (error) {
if (axios.isAxiosError(error)) {
const statusCode = error.response?.status
const errMsg = error?.response?.data || 'INTERNAL SERVER ERROR'

switch (statusCode) {
case 401:
throw new Error('Error deleting the question: Unauthorized')
case 404:
throw new Error('Error deleting the question: No such user!')
default:
throw new Error('An unexpected error occurred: ' + error.message)
throw new Error('An unexpected error occurred: ' + errMsg)
}
} else {
throw new Error('An unexpected error occurred')
Expand All @@ -161,7 +166,8 @@ export const getQuestionCountsRequest = async (): Promise<IQuestionCountsDto | u
return response
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error('An unexpected error occurred: ' + error.message)
const errMsg = error?.response?.data || 'INTERNAL SERVER ERROR'
throw new Error('An unexpected error occurred: ' + errMsg)
} else {
throw new Error('An unexpected error occurred')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/collaboration-types/src/LanguageMode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export enum LanguageMode {
Csharp = 'csharp',
Csharp = 'CSharp',
Golang = 'Go',
Javascript = 'Javascript',
Java = 'Java',
Python = 'Python',
Ruby = 'ruby',
Ruby = 'Ruby',
Typescript = 'Typescript',
}

Expand Down

0 comments on commit d49d36d

Please sign in to comment.