-
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.
- Loading branch information
Showing
8 changed files
with
149 additions
and
27 deletions.
There are no files selected for viewing
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,30 @@ | ||
CREATE MIGRATION m1poydrr4wqnyyw2kuxdyz2gkxhomo27tud2b5imhloezqgvhd7spa | ||
ONTO m1g7zzumkuvubppu53mcmxqcs73v2xyvueiz3cshqj75qd4uy2qafq | ||
{ | ||
ALTER TYPE default::Assignment { | ||
ALTER LINK completedBy { | ||
ON TARGET DELETE ALLOW; | ||
}; | ||
ALTER LINK updatedBy { | ||
ON TARGET DELETE ALLOW; | ||
}; | ||
}; | ||
ALTER TYPE default::Class { | ||
ALTER LINK students { | ||
ON TARGET DELETE ALLOW; | ||
}; | ||
}; | ||
ALTER TYPE default::JoinRequest { | ||
ALTER LINK reviewedBy { | ||
ON TARGET DELETE ALLOW; | ||
}; | ||
ALTER LINK user { | ||
ON TARGET DELETE DELETE SOURCE; | ||
}; | ||
}; | ||
ALTER TYPE default::User { | ||
ALTER LINK tokens { | ||
ON SOURCE DELETE DELETE TARGET; | ||
}; | ||
}; | ||
}; |
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,32 @@ | ||
CREATE MIGRATION m1hmgl6ihppy3vtahtblnbmpvhbrn7vtjhloj5f7f2e6qgwsn7eqgq | ||
ONTO m1poydrr4wqnyyw2kuxdyz2gkxhomo27tud2b5imhloezqgvhd7spa | ||
{ | ||
ALTER TYPE default::User { | ||
DROP LINK assignments; | ||
}; | ||
ALTER TYPE default::Assignment { | ||
DROP LINK updatedBy; | ||
}; | ||
ALTER TYPE default::Assignment { | ||
DROP PROPERTY updates; | ||
}; | ||
CREATE TYPE default::Change { | ||
CREATE REQUIRED LINK user: default::User { | ||
ON TARGET DELETE DELETE SOURCE; | ||
}; | ||
CREATE REQUIRED PROPERTY time: std::datetime { | ||
SET default := (std::datetime_current()); | ||
}; | ||
}; | ||
ALTER TYPE default::Assignment { | ||
CREATE MULTI LINK updates: default::Change { | ||
ON TARGET DELETE ALLOW; | ||
}; | ||
}; | ||
ALTER TYPE default::Change { | ||
CREATE LINK assignments := (.<updates[IS default::Assignment]); | ||
}; | ||
ALTER TYPE default::User { | ||
CREATE LINK changes := (.<user[IS default::Change]); | ||
}; | ||
}; |
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 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,42 @@ | ||
import e from "@edgedb"; | ||
import { | ||
DATABASE_DELETE_FAILED, | ||
MUST_BE_GENERATED_BY_LOGIN_NOT_REFRESH, | ||
UNAUTHORIZED, | ||
} from "constants/responses"; | ||
import Elysia from "elysia"; | ||
import { HttpStatusCode } from "elysia-http-status-code"; | ||
import { client } from "index"; | ||
import { auth } from "plugins/auth"; | ||
import { promiseResult } from "utils/errors"; | ||
import { responseBuilder } from "utils/response"; | ||
|
||
export const deleteUser = new Elysia() | ||
.use(auth) | ||
.use(HttpStatusCode()) | ||
.delete("/", async ({ auth, httpStatus, set }) => { | ||
if (!auth.isAuthorized) { | ||
set.status = httpStatus.HTTP_401_UNAUTHORIZED; | ||
return UNAUTHORIZED; | ||
} | ||
if (auth.createdBy !== "login") { | ||
set.status = httpStatus.HTTP_403_FORBIDDEN; | ||
return MUST_BE_GENERATED_BY_LOGIN_NOT_REFRESH; | ||
} | ||
|
||
const query = e.delete(e.User, (u) => ({ | ||
filter_single: e.op(u.username, "=", auth.username), | ||
})); | ||
|
||
const result = await promiseResult(() => query.run(client)); | ||
|
||
if (result.isError || !result.data) { | ||
set.status = httpStatus.HTTP_500_INTERNAL_SERVER_ERROR; | ||
return DATABASE_DELETE_FAILED; | ||
} | ||
|
||
return responseBuilder("success", { | ||
message: "Successfully deleted user", | ||
data: null, | ||
}); | ||
}); |
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