Skip to content

Commit

Permalink
Delete ship sheet sections (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrod-lowe authored Oct 13, 2024
1 parent 44c79dc commit c9f3bd8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { util, Context, AppSyncIdentityCognito } from "@aws-appsync/utils";
import type { DynamoDBDeleteItemRequest } from "@aws-appsync/utils/lib/resolver-return-types";
import { SheetSection, DeleteSectionInput } from "../../../appsync/graphql";
import { DDBPrefixGame, DDBPrefixSection } from "../../lib/constants";
import { DDBPrefixGame, DDBPrefixSection, TypeShip } from "../../lib/constants";

export function request(
context: Context<{ input: DeleteSectionInput }>,
Expand All @@ -24,19 +24,23 @@ export function request(
}),
operation: "DeleteItem",
condition: {
expression: "#userId = :userId",
expression: "#userId = :userId OR #playerType = :playerType",
expressionNames: {
"#userId": "userId",
"#playerType": "playerType",
},
expressionValues: {
":userId": { S: identity.sub },
},
expressionValues: util.dynamodb.toMapValues({
":userId": identity.sub,
":playerType": TypeShip,
}),
},
};
}

export function response(context: Context): SheetSection | null {
if (context.error) {
if (context.error.type === "DynamoDB:ConditionalCheckFailedException")
util.unauthorized();
util.error(context.error.message, context.error.type, context.result);
}

Expand Down
9 changes: 2 additions & 7 deletions graphql/function/updateSection/updateSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ interface UpdateType {
export function request(
context: Context<{ input: UpdateSectionInput }>,
): DynamoDBUpdateItemRequest {
if (!context.identity) {
util.error("Unauthorized: Identity information is missing." as string);
}

if (!context.identity) util.unauthorized();
const identity = context.identity as AppSyncIdentityCognito;
if (!identity?.sub) {
util.error("Unauthorized: User ID is missing." as string);
}
if (!identity?.sub) util.unauthorized();

const input = context.arguments.input;
const timestamp = util.time.nowISO8601();
Expand Down
4 changes: 4 additions & 0 deletions terraform/module/wildsea/graphql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ locals {
type : "Mutation",
functions = ["checkGameAccess", "updateSection"]
}
deleteSection = {
type : "Mutation",
functions = ["checkGameAccess", "deleteSection"]
}
deletePlayer = {
type : "Mutation",
functions = ["checkPlayerSheetAccessWithFirefly", "findAllSections", "deletePlayer"]
Expand Down
2 changes: 2 additions & 0 deletions ui/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const messages = {
'sectionName': 'Name',
'save': 'Save Changes',
'cancel': 'Cancel',
'close': 'Close',
'characterName': 'Character Name',
'playerSheetTab.updateError': 'Failed to update the character name. Please try again.',
'playerSheetTab.createSectionError': 'Failed to create a new section. Please try again.',
Expand All @@ -54,6 +55,7 @@ export const messages = {
'playerSheetTab.addSection': 'Add a section',
'playerSheetTab.deleteSection': 'Delete a section',
'playerSheetTab.deleteSectionWarning': 'Deleting a section is permanent and cannot be undone. All data within the section will be lost.',
'playerSheetTab.deleteSectionError': 'Failed to create deltete the section. Please try again.',
'playerSheetTab.quitLabel': 'Quit Game',
'playerSheetTab.kickShipLabel': 'Delete Ship',
'playerSheetTab.kickPlayerLabel': 'Kick Player',
Expand Down

0 comments on commit c9f3bd8

Please sign in to comment.