diff --git a/packages/zero/schema.ts b/packages/zero/schema.ts index b6086c78..a2956397 100644 --- a/packages/zero/schema.ts +++ b/packages/zero/schema.ts @@ -1,5 +1,5 @@ -import type { Size, Links} from "@nestri/core/src/base-game/base-game.sql"; import type { Limitations } from "@nestri/core/src/steam/steam.sql"; +import type { Size, Links } from "@nestri/core/src/base-game/base-game.sql"; import type { ImageColor, ImageDimensions } from "@nestri/core/src/images/images.sql"; import { json, @@ -47,27 +47,6 @@ const steam_accounts = table("steam_accounts") }) .primaryKey("id"); -const teams = table("teams") - .columns({ - id: string(), - name: string(), - invite_code: string(), - max_members: number(), - owner_steam_id: string(), - ...timestamps, - }) - .primaryKey("id"); - -const members = table("members") - .columns({ - role: string(), - team_id: string(), - steam_id: string(), - user_id: string().optional(), - ...timestamps, - }) - .primaryKey("team_id", "steam_id"); - const friends_list = table("friends_list") .columns({ steam_id: string(), @@ -130,11 +109,11 @@ const images = table("images") dimensions: json(), extracted_color: json(), ...timestamps - }).primaryKey("image_hash", "type", "base_game_id", "position") + }).primaryKey("image_hash") // Schema and Relationships export const schema = createSchema({ - tables: [users, steam_accounts, teams, members, friends_list, categories, base_games, games, game_libraries, images], + tables: [users, steam_accounts, friends_list, categories, base_games, games, game_libraries, images], relationships: [ relationships(steam_accounts, (r) => ({ user: r.one({ @@ -142,16 +121,6 @@ export const schema = createSchema({ destSchema: users, destField: ["id"], }), - memberEntries: r.many({ - sourceField: ["id"], - destSchema: members, - destField: ["steam_id"], - }), - teams: r.many({ - sourceField: ["id"], - destSchema: teams, - destField: ["owner_steam_id"], - }), friends: r.many( { sourceField: ["id"], @@ -178,46 +147,12 @@ export const schema = createSchema({ ), })), relationships(users, (r) => ({ - members: r.many({ - sourceField: ["id"], - destSchema: members, - destField: ["user_id"], - }), steamAccounts: r.many({ sourceField: ["id"], destSchema: steam_accounts, destField: ["user_id"] }) })), - relationships(teams, (r) => ({ - owner: r.one({ - sourceField: ["owner_steam_id"], - destSchema: steam_accounts, - destField: ["id"], - }), - members: r.many({ - sourceField: ["id"], - destSchema: members, - destField: ["team_id"], - }), - })), - relationships(members, (r) => ({ - team: r.one({ - sourceField: ["team_id"], - destSchema: teams, - destField: ["id"], - }), - user: r.one({ - sourceField: ["user_id"], - destSchema: users, - destField: ["id"], - }), - steamAccount: r.one({ - sourceField: ["steam_id"], - destSchema: steam_accounts, - destField: ["id"], - }), - })), relationships(base_games, (r) => ({ libraryOwners: r.many( { @@ -324,30 +259,12 @@ type Auth = { export const permissions = definePermissions(schema, () => { return { - members: { - row: { - select: [ - (auth: Auth, q: ExpressionBuilder) => q.exists("user", (u) => u.where("id", auth.sub)), - //allow other team members to view other members - (auth: Auth, q: ExpressionBuilder) => q.exists("team", (u) => u.related("members", (m) => m.where("user_id", auth.sub))), - ] - }, - }, - teams: { - row: { - select: [ - (auth: Auth, q: ExpressionBuilder) => q.exists("members", (u) => u.where("user_id", auth.sub)), - ] - }, - }, steam_accounts: { row: { select: [ (auth: Auth, q: ExpressionBuilder) => q.exists("user", (u) => u.where("id", auth.sub)), //Allow friends to view friends steam accounts (auth: Auth, q: ExpressionBuilder) => q.exists("friends", (u) => u.where("user_id", auth.sub)), - //allow other team members to see a user's steam account - (auth: Auth, q: ExpressionBuilder) => q.exists("memberEntries", (u) => u.related("team", (t) => t.related("members", (m) => m.where("user_id", auth.sub)))), ] }, }, @@ -370,8 +287,6 @@ export const permissions = definePermissions(schema, () => { row: { select: [ (auth: Auth, q: ExpressionBuilder) => q.exists("owner", (u) => u.where("user_id", auth.sub)), - //allow team members to see the other members' libraries - (auth: Auth, q: ExpressionBuilder) => q.exists("owner", (u) => u.related("memberEntries", (f) => f.where("user_id", auth.sub))), //allow friends to see their friends libraries (auth: Auth, q: ExpressionBuilder) => q.exists("owner", (u) => u.related("friends", (f) => f.where("user_id", auth.sub))), ]