From 40e747624d674e383089d603cc7b4f788b74193f Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 8 Jul 2024 14:49:57 +0200 Subject: [PATCH] feat: set drive icon mutation --- api/package.json | 2 +- api/pnpm-lock.yaml | 14 +++++------ .../graphql/server/generated/index/nexus.ts | 9 +++++++ .../server/generated/index/schema.graphql | 5 ++++ .../modules/document-drive/drives-resolver.ts | 24 +++++++++++++++++++ api/src/modules/document/model.ts | 3 +++ 6 files changed, 49 insertions(+), 8 deletions(-) diff --git a/api/package.json b/api/package.json index 27e08ce6..c6546993 100644 --- a/api/package.json +++ b/api/package.json @@ -30,7 +30,7 @@ "cors": "^2.8.5", "document-drive": "1.0.0-alpha.80", "document-model": "1.7.0", - "document-model-libs": "^1.69.0", + "document-model-libs": "^1.70.0", "dotenv": "^16.4.5", "esbuild": "^0.21.2", "ethers": "^5.7.2", diff --git a/api/pnpm-lock.yaml b/api/pnpm-lock.yaml index 1fc1c0fc..b30f9018 100644 --- a/api/pnpm-lock.yaml +++ b/api/pnpm-lock.yaml @@ -34,13 +34,13 @@ dependencies: version: 2.8.5 document-drive: specifier: 1.0.0-alpha.80 - version: 1.0.0-alpha.80(document-model-libs@1.69.0)(document-model@1.7.0)(prisma@5.16.0) + version: 1.0.0-alpha.80(document-model-libs@1.70.0)(document-model@1.7.0)(prisma@5.16.0) document-model: specifier: 1.7.0 version: 1.7.0 document-model-libs: - specifier: ^1.69.0 - version: 1.69.0(graphql@16.9.0)(react-dom@18.3.1)(react@18.3.1)(vitest@0.32.4) + specifier: ^1.70.0 + version: 1.70.0(graphql@16.9.0)(react-dom@18.3.1)(react@18.3.1)(vitest@0.32.4) dotenv: specifier: ^16.4.5 version: 16.4.5 @@ -5817,14 +5817,14 @@ packages: esutils: 2.0.3 dev: true - /document-drive@1.0.0-alpha.80(document-model-libs@1.69.0)(document-model@1.7.0)(prisma@5.16.0): + /document-drive@1.0.0-alpha.80(document-model-libs@1.70.0)(document-model@1.7.0)(prisma@5.16.0): resolution: {integrity: sha512-SrkJrU2S+LyJcaBSf0wh59zX5M8G14b2eLguIj3/qj4dCwNGgiTav1WQhAaq65VM7ojY9NSurqJqvBLcSvrdEg==} peerDependencies: document-model: ^1.7.0 document-model-libs: ^1.57.0 dependencies: document-model: 1.7.0 - document-model-libs: 1.69.0(graphql@16.9.0)(react-dom@18.3.1)(react@18.3.1)(vitest@0.32.4) + document-model-libs: 1.70.0(graphql@16.9.0)(react-dom@18.3.1)(react@18.3.1)(vitest@0.32.4) exponential-backoff: 3.1.1 graphql: 16.9.0 graphql-request: 6.1.0(graphql@16.9.0) @@ -5853,8 +5853,8 @@ packages: - tedious dev: false - /document-model-libs@1.69.0(graphql@16.9.0)(react-dom@18.3.1)(react@18.3.1)(vitest@0.32.4): - resolution: {integrity: sha512-l26Jzw/4W3ldcHnyxq7EPzX5JwSQkYiz6eBnotofUF2QBukIGTpD9nluuKCrEXCeahLxeLvHJJJN36CZrSsYzg==} + /document-model-libs@1.70.0(graphql@16.9.0)(react-dom@18.3.1)(react@18.3.1)(vitest@0.32.4): + resolution: {integrity: sha512-dQ/GQmutBcwDgCug/HRjlCZ/4tl0xtA1L6K7m4gMPj1DAsA+GBqR9oFBlzMd8Ds9iNMqpj2Z1Jr9x7Iah+H6Nw==} peerDependencies: react: ^18.2.0 react-dom: ^18.2.0 diff --git a/api/src/graphql/server/generated/index/nexus.ts b/api/src/graphql/server/generated/index/nexus.ts index 920e4fb8..c3ce4b80 100644 --- a/api/src/graphql/server/generated/index/nexus.ts +++ b/api/src/graphql/server/generated/index/nexus.ts @@ -63,6 +63,9 @@ export interface NexusGenInputs { expiryDurationSeconds?: number | null; // Int name: string; // String! } + SetDriveIconInput: { // input type + icon: string; // String! + } } export interface NexusGenEnums { @@ -193,6 +196,7 @@ export interface NexusGenFieldTypes { createSession: NexusGenRootTypes['SessionOutput'] | null; // SessionOutput deleteDrive: boolean | null; // Boolean revokeSession: NexusGenRootTypes['Session'] | null; // Session + setDriveIcon: boolean | null; // Boolean solveChallenge: NexusGenRootTypes['SessionOutput'] | null; // SessionOutput } Node: { // field return type @@ -277,6 +281,7 @@ export interface NexusGenFieldTypeNames { createSession: 'SessionOutput' deleteDrive: 'Boolean' revokeSession: 'Session' + setDriveIcon: 'Boolean' solveChallenge: 'SessionOutput' } Node: { // field return type name @@ -338,6 +343,10 @@ export interface NexusGenArgTypes { revokeSession: { // args sessionId: string; // String! } + setDriveIcon: { // args + icon: string; // String! + id: string; // String! + } solveChallenge: { // args nonce: string; // String! signature: string; // String! diff --git a/api/src/graphql/server/generated/index/schema.graphql b/api/src/graphql/server/generated/index/schema.graphql index b6b05394..e76b3453 100644 --- a/api/src/graphql/server/generated/index/schema.graphql +++ b/api/src/graphql/server/generated/index/schema.graphql @@ -66,6 +66,7 @@ type Mutation { createSession(session: SessionInput!): SessionOutput deleteDrive(id: String!): Boolean revokeSession(sessionId: String!): Session + setDriveIcon(icon: String!, id: String!): Boolean solveChallenge(nonce: String!, signature: String!): SessionOutput } @@ -108,6 +109,10 @@ type SessionOutput { token: String! } +input SetDriveIconInput { + icon: String! +} + type SwitchboardHost implements System { auth: Auth } diff --git a/api/src/modules/document-drive/drives-resolver.ts b/api/src/modules/document-drive/drives-resolver.ts index a357b133..b40c5d39 100644 --- a/api/src/modules/document-drive/drives-resolver.ts +++ b/api/src/modules/document-drive/drives-resolver.ts @@ -37,6 +37,13 @@ export const DocumentDriveStateInput = inputObjectType({ }, }); +export const SetDriveIconInput = inputObjectType({ + name: "SetDriveIconInput", + definition(t) { + t.nonNull.string("icon") + } +}); + export const getDrives = queryField('drives', { type: list('String'), resolve: async (_parent, args, ctx: Context) => { @@ -113,3 +120,20 @@ export const deleteDrive = mutationField('deleteDrive', { return true; }, }); + +export const setDriveIcon = mutationField('setDriveIcon', { + type: 'Boolean', + args: { + id: nonNull('String'), + icon: nonNull('String'), + }, + resolve: async (_parent, { id, icon }, ctx: Context) => { + try { + await ctx.prisma.document.setDriveIcon(id, icon); + } catch (e: any) { + throw new DocumentDriveError({ code: 500, message: e.message ?? "Failed to set drive icon", logging: true, context: e }) + } + + return true; + } +}); diff --git a/api/src/modules/document/model.ts b/api/src/modules/document/model.ts index 5a946306..80741a2f 100644 --- a/api/src/modules/document/model.ts +++ b/api/src/modules/document/model.ts @@ -247,6 +247,9 @@ export function getDocumentDriveCRUD(prisma: Prisma.TransactionClient) { return documents; }, + setDriveIcon: async (driveId: string, icon: string) => { + return await driveServer.queueDriveAction(driveId, actions.setDriveIcon({ icon })); + }, closeScopeOfWorkIssue: async (githubId: number) => { // const dbEntry = await prisma.scopeOfWorkDeliverable.findFirst({ // where: {