Skip to content

Commit

Permalink
overall bug fixes and improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak committed May 5, 2024
1 parent 2dc39b1 commit 3641bac
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 52 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@elysiajs/bearer": "^1.0.2",
"@elysiajs/cors": "^1.0.2",
"@elysiajs/swagger": "^1.0.3",
"edgedb": "^1.4.1",
"elysia": "latest",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cors } from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import { DOCUMENTATION_OPTIONS } from "constants/documentation";
import { VERSION } from "constants/general";
Expand Down Expand Up @@ -28,6 +29,7 @@ const app = new Elysia()
.use(calendarRouter)
.use(tagRouter)
.use(noteRouter)
.use(cors())
.get(
"/",
() => ({
Expand Down
5 changes: 1 addition & 4 deletions src/routes/assignments/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ export const listAssignments = new Elysia().use(HttpStatusCode()).get(
updates: () => ({
user: () => ({ username: true, displayname: true }),
time: true,
updates: () => ({
user: () => ({ username: true, displayname: true }),
time: true,
}),
}),
id: true,
};
Expand All @@ -153,6 +149,7 @@ export const listAssignments = new Elysia().use(HttpStatusCode()).get(
});

if (result.isError) {
console.log(result.error);
set.status = httpStatus.HTTP_500_INTERNAL_SERVER_ERROR;
return DATABASE_READ_FAILED;
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/classes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getClass = new Elysia().use(HttpStatusCode()).get(
limit: query.limit,
offset: query.offset,
filter: query.query
? e.op(c.name, "like", `%${query.query}%`)
? e.op(e.str_lower(c.name), "like", `%${query.query.toLowerCase()}%`)
: undefined,

name: true,
Expand Down
113 changes: 67 additions & 46 deletions src/routes/moderation/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,78 @@ import { responseBuilder } from "utils/response";
export const listJoinRequests = new Elysia()
.use(HttpStatusCode())
.use(auth)
.get("/", async ({ set, auth, httpStatus }) => {
if (!auth.isAuthorized) {
set.status = httpStatus.HTTP_401_UNAUTHORIZED;
return UNAUTHORIZED;
}
.get(
"/",
async ({ set, auth, httpStatus, query }) => {
if (!auth.isAuthorized) {
set.status = httpStatus.HTTP_401_UNAUTHORIZED;
return UNAUTHORIZED;
}

const joinRequestsQuery = e.select(e.JoinRequest, (jr) => {
const classMatches = e.op(
jr.wantsToJoin.students.username,
"=",
auth.username,
);
const joinRequestsQuery = e.select(e.JoinRequest, (jr) => {
const classMatches = e.op(
jr.wantsToJoin.students.username,
"=",
auth.username,
);

return {
filter: classMatches,
const type = query.type || "all";
const statusMatches =
type === "all"
? e.cast(e.bool, true)
: e.op(jr.status, "=", e.cast(e.Status, type));

user: () => ({
username: true,
displayname: true,
created: true,
classes: () => ({
return {
filter: e.op(classMatches, "and", statusMatches),

user: () => ({
username: true,
displayname: true,
created: true,
classes: () => ({
name: true,
school: () => ({ name: true }),
}),
}),
wantsToJoin: () => ({
name: true,
school: () => ({ name: true }),
}),
}),
wantsToJoin: () => ({
name: true,
school: () => ({ name: true }),
}),
status: true,
created: true,
reviewedAt: true,
reviewedBy: () => ({
username: true,
displayname: true,
}),
id: true,
};
});
const joinRequests = await promiseResult(() =>
joinRequestsQuery.run(client),
);
status: true,
created: true,
reviewedAt: true,
reviewedBy: () => ({
username: true,
displayname: true,
}),
id: true,
};
});
const joinRequests = await promiseResult(() =>
joinRequestsQuery.run(client),
);

if (joinRequests.isError) {
set.status = httpStatus.HTTP_500_INTERNAL_SERVER_ERROR;
return DATABASE_READ_FAILED;
}
if (joinRequests.isError) {
set.status = httpStatus.HTTP_500_INTERNAL_SERVER_ERROR;
return DATABASE_READ_FAILED;
}

const responseData = joinRequests.data.map(replaceDateWithTimestamp);
return responseBuilder("success", {
message: `Successfully retrieved join requests ${auth.username} can review`,
data: responseData,
});
});
const responseData = joinRequests.data.map(replaceDateWithTimestamp);
return responseBuilder("success", {
message: `Successfully retrieved join requests ${auth.username} can review`,
data: responseData,
});
},
{
query: t.Object({
type: t.Optional(
t.Union([
t.Literal("all"),
t.Literal("Pending"),
t.Literal("Accepted"),
t.Literal("Rejected"),
]),
),
}),
},
);
6 changes: 5 additions & 1 deletion src/routes/school/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const getSchools = new Elysia().use(HttpStatusCode()).get(
"/",
async ({ query: { limit, offset, query }, set, httpStatus }) => {
const schoolsQuery = e.select(e.School, (s) => {
const isLikeName = e.op(s.name, "like", `%${query}%`);
const isLikeName = e.op(
e.str_lower(s.name),
"like",
`%${query?.toLowerCase()}%`,
);
const isLikeDescription = e.op(s.description, "like", `%${query}%`);

const useFilter = !!query;
Expand Down
6 changes: 6 additions & 0 deletions src/routes/user/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export const userInfoRouter = new Elysia({ prefix: "/info" })
username: true,
displayname: true,
created: isThemself,
classes: isThemself
? () => ({
name: true,
school: () => ({ name: true }),
})
: false,
filter_single: e.op(u.username, "=", username),
}));

Expand Down

0 comments on commit 3641bac

Please sign in to comment.