Skip to content

Instantly share code, notes, and snippets.

@GregRos
Last active October 13, 2022 14:07
Show Gist options
  • Save GregRos/9ea8087afb4588c1f661b2a66a28513c to your computer and use it in GitHub Desktop.
Save GregRos/9ea8087afb4588c1f661b2a66a28513c to your computer and use it in GitHub Desktop.
let USER = 1000;
// Logs user in using `auth`
export async function login(auth) { /* ... */ }
// Gets a list of all squmbles of the user
export async function getSqumbles() { /* ... */ }
// Gets squmble by ID
export async function getSqumble(id) { /* ... */ }
// Updates the squggle. Data must include id.
export async function updateSquggle(data) { /* ... */ }
// Deletes squmble by ID
export async function deleteSqumble(id) { /* ... */ }
// Creates a squagel.
// @returns {number} The created squagel ID.
export async function createSquagel(data) { /* ... */ }
// Updates the squggle by id
export async function updateSqumble(data) {
const owner = await getSquggleOwnerInfo(data.id)
if (!USER) {
throw new Error("Not logged in")
}
if (owner.id !== USER) {
if (!owner.isTeam) {
throw new Error("Owner not a team")
}
const perms = await getUserTeamPermissions(owner.id)
if (!perms) {
throw new Error("User not member of team")
}
if ("name" in data && perms !== "ADMIN") {
throw new Error("Not enough permissions")
}
if (perms !== "WRITE" && perms === "ADMIN") {
throw new Error("Not enough permissions")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment