Skip to content

Commit

Permalink
setStorage -> setStorages
Browse files Browse the repository at this point in the history
  • Loading branch information
kgtkr committed Jan 16, 2024
1 parent 40b6b0e commit be819fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
15 changes: 14 additions & 1 deletion packages/server/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ type CreateClientResponseError {

union CreateClientResponse = Client | CreateClientResponseError

input SetStoragesInput {
storages: [StorageInput!]!
}

input StorageInput {
key: String!
value: String!
}

type SetStoragesPayload {
storages: [Storage!]!
}

type Mutation {
createClient(name: String!, url: String!): Client!
updateClient(id: ID!, name: String, url: String): Client!
Expand All @@ -458,7 +471,7 @@ type Mutation {
): ResNormal!
voteRes(res: ID!, type: VoteType!): Res!
delRes(res: ID!): ResDelete!
setStorage(key: String!, value: String!): Storage!
setStorages(input: SetStoragesInput!): SetStoragesPayload!
delStorage(key: String!): Boolean
delTokenClient(client: ID!): Boolean
createTokenGeneral(client: ID!): CreateTokenGeneralResponse!
Expand Down
24 changes: 16 additions & 8 deletions packages/server/src/resolvers/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fromNullable, some } from "fp-ts/lib/Option";
import { AtNotFoundError } from "../at-error";
import {
Client,
IStorageAPI,
Profile,
ResNormal,
Storage,
Expand Down Expand Up @@ -283,14 +284,21 @@ export const mutation: G.MutationResolvers = {
}
return api;
},
setStorage: async (_obj, args, context, _info) => {
const storage = Storage.create(
context.ports.authContainer.getToken(),
args.key,
args.value
);
await context.ports.storageRepo.save(storage);
return storage.toAPI(context.ports.authContainer.getToken());
setStorages: async (_obj, args, context, _info) => {
// TODO: トランザクション
const results: IStorageAPI[] = [];
for (const storageInput of args.input.storages) {
const storage = Storage.create(
context.ports.authContainer.getToken(),
storageInput.key,
storageInput.value
);
await context.ports.storageRepo.save(storage);
results.push(storage.toAPI(context.ports.authContainer.getToken()));
}
return {
storages: results,
};
},
delStorage: async (_obj, args, context, _info) => {
const storage = await context.ports.storageRepo.findOneKey(
Expand Down

0 comments on commit be819fe

Please sign in to comment.