Skip to content

Commit

Permalink
Update ship name (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrod-lowe authored Oct 13, 2024
1 parent c9f3bd8 commit 89f5136
Show file tree
Hide file tree
Showing 30 changed files with 121 additions and 228 deletions.
12 changes: 6 additions & 6 deletions appsync/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type Mutation = {
deleteSection: SheetSection;
joinGame: GameSummary;
updateGame: GameSummary;
updatePlayerSheet?: Maybe<PlayerSheetSummary>;
updatePlayer?: Maybe<PlayerSheetSummary>;
updateSection: SheetSection;
};

Expand Down Expand Up @@ -134,8 +134,8 @@ export type MutationUpdateGameArgs = {
};


export type MutationUpdatePlayerSheetArgs = {
input: UpdatePlayerSheetInput;
export type MutationUpdatePlayerArgs = {
input: UpdatePlayerInput;
};


Expand Down Expand Up @@ -197,7 +197,7 @@ export type SheetSection = {
export type Subscription = {
__typename?: 'Subscription';
updatedGame?: Maybe<GameSummary>;
updatedPlayerSheet?: Maybe<PlayerSheetSummary>;
updatedPlayer?: Maybe<PlayerSheetSummary>;
updatedSection?: Maybe<SheetSection>;
};

Expand All @@ -207,7 +207,7 @@ export type SubscriptionUpdatedGameArgs = {
};


export type SubscriptionUpdatedPlayerSheetArgs = {
export type SubscriptionUpdatedPlayerArgs = {
gameId: Scalars['ID']['input'];
};

Expand All @@ -222,7 +222,7 @@ export type UpdateGameInput = {
name: Scalars['String']['input'];
};

export type UpdatePlayerSheetInput = {
export type UpdatePlayerInput = {
characterName: Scalars['String']['input'];
gameId: Scalars['ID']['input'];
userId: Scalars['ID']['input'];
Expand Down
12 changes: 6 additions & 6 deletions appsync/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
}
`;

export const updatePlayerSheetMutation = `
mutation updatePlayerSheet($input: UpdatePlayerSheetInput!) {
updatePlayerSheet(input: $input) {
export const updatePlayerMutation = `
mutation updatePlayer($input: UpdatePlayerInput!) {
updatePlayer(input: $input) {
userId gameId gameName gameDescription characterName type createdAt updatedAt deleted
}
}
Expand All @@ -92,9 +92,9 @@



export const updatedPlayerSheetSubscription = `
subscription updatedPlayerSheet($gameId: ID!) {
updatedPlayerSheet(gameId: $gameId) {
export const updatedPlayerSubscription = `
subscription updatedPlayer($gameId: ID!) {
updatedPlayer(gameId: $gameId) {
userId gameId gameName gameDescription characterName type createdAt updatedAt deleted
}
}
Expand Down
8 changes: 4 additions & 4 deletions design/PLANNING.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ input CreatePlayerSheetInput {
fireflyNotes: String
}

input UpdatePlayerSheetInput {
input updatePlayerInput {
characterName: String
pronouns: String
bloodline: String
Expand Down Expand Up @@ -775,7 +775,7 @@ type Mutation {
createGame(input: CreateGameInput!): Game!
updateGame(id: ID!, input: UpdateGameInput!): Game!
createPlayerSheet(input: CreatePlayerSheetInput!): PlayerSheet!
updatePlayerSheet(id: ID!, input: UpdatePlayerSheetInput!): PlayerSheet!
updatePlayer(id: ID!, input: updatePlayerInput!): PlayerSheet!
createShipSheet(input: CreateShipSheetInput!): ShipSheet!
updateShipSheet(id: ID!, input: UpdateShipSheetInput!): ShipSheet!
createClock(input: CreateClockInput!): Clock!
Expand All @@ -790,8 +790,8 @@ type Subscription {
@aws_subscribe(mutations: ["updateUser"])
onCreatePlayerSheet(gameId: ID!): PlayerSheet
@aws_subscribe(mutations: ["createPlayerSheet"])
onUpdatePlayerSheet(id: ID!): PlayerSheet
@aws_subscribe(mutations: ["updatePlayerSheet"])
onupdatePlayer(id: ID!): PlayerSheet
@aws_subscribe(mutations: ["updatePlayer"])
onCreateShipSheet(gameId: ID!): ShipSheet
@aws_subscribe(mutations: ["createShipSheet"])
onUpdateShipSheet(id: ID!): ShipSheet
Expand Down
5 changes: 1 addition & 4 deletions graphql/function/checkGameAccess/checkGameAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { DDBPrefixGame } from "../../lib/constants";
export function request(
context: Context<{ input: GetGameInput }>,
): DynamoDBGetItemRequest {
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.unauthorized();

Expand Down
20 changes: 4 additions & 16 deletions graphql/function/checkGameFireflyAccess/checkGameFireflyAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ import { DDBPrefixGame } from "../../lib/constants";
export function request(
context: Context<{ input: GetGameInput }>,
): DynamoDBGetItemRequest {
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 id = context.args.input.gameId;
const key = {
Expand Down Expand Up @@ -42,15 +37,8 @@ export function response(context: ResponseContext): DataGame | undefined {
}

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

if (!permitted(identity, context.result)) {
util.error(
"Unauthorized: User does not have access to the game." as string,
);
}
if (!identity?.sub) util.unauthorized();
if (!permitted(identity, context.result)) util.unauthorized();

return context.result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ import { authIsIam } from "../../lib/auth";
export function request(
context: Context<{ input: DeletePlayerInput }>,
): DynamoDBGetItemRequest {
if (!context.identity) {
util.error("Unauthorized: Identity information is missing." as string);
}

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

const gameId = context.arguments.input.gameId;
Expand Down Expand Up @@ -52,18 +47,14 @@ export function response(

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

if (
context.result === undefined ||
(identity.sub != context.result.userId &&
identity.sub != context.result.fireflyUserId)
) {
util.error(
"Unauthorized: User does not have access to the player sheet." as string,
);
util.unauthorized();
}
}

Expand Down
9 changes: 2 additions & 7 deletions graphql/function/deleteSection/deleteSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ import { DDBPrefixGame, DDBPrefixSection, TypeShip } from "../../lib/constants";
export function request(
context: Context<{ input: DeleteSectionInput }>,
): DynamoDBDeleteItemRequest {
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;

Expand Down
9 changes: 2 additions & 7 deletions graphql/function/findAllPlayers/findAllPlayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import { DDBPrefixGame, DDBPrefixPlayer } from "../../lib/constants";
export function request(
context: Context<{ input: DeletePlayerInput }>,
): DynamoDBQueryRequest {
if (!context.identity) {
util.error("Unauthorized: Identity information is missing.");
}

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

const input = context.arguments.input;

Expand Down
9 changes: 2 additions & 7 deletions graphql/function/getGame/getGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ export function request(
}

function validateIdentity(context: Context<QueryGetGameArgs>): void {
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();
}

function buildDynamoDBQuery(id: string): DynamoDBQueryRequest {
Expand Down
14 changes: 3 additions & 11 deletions graphql/function/getGameWithToken/getGameWithToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ import { DDBPrefixGame } from "../../lib/constants";
export function request(
context: Context<{ input: JoinGameInput }>,
): DynamoDBGetItemRequest {
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 id = context.arguments.input.gameId;
const key = {
Expand All @@ -38,10 +33,7 @@ export function response(
context.result === null ||
context.result.joinToken !== context.arguments.input.joinToken
) {
util.error(
"Game not found or invalid token" as string,
"AccessDeniedException",
);
util.unauthorized();
}

const identity = context.identity as AppSyncIdentityCognito;
Expand Down
9 changes: 2 additions & 7 deletions graphql/function/joinGame/joinGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ import {
import { DataPlayerSheet } from "../../lib/dataTypes";

export function request(context: Context<{ input: JoinGameInput }>): unknown {
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 id = context.arguments.input.gameId;
const timestamp = util.time.nowISO8601();
Expand Down
8 changes: 2 additions & 6 deletions graphql/function/updateGame/updateGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ export function request(
const { gameId, name, description } = context.arguments.input;
const timestamp = util.time.nowISO8601();

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();

return {
operation: "UpdateItem",
Expand Down
9 changes: 2 additions & 7 deletions graphql/function/updateGameOnPlayers/updateGameOnPlayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ type UserIdItem = {
};

export function request(context: Context<{ input: UpdateGameInput }>): unknown {
if (!context.identity) {
util.error("Unauthorized: Identity information is missing.");
}

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

const timestamp = util.time.nowISO8601();
context.stash.updatedAt = timestamp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import { util, Context, AppSyncIdentityCognito } from "@aws-appsync/utils";
import type { DynamoDBUpdateItemRequest } from "@aws-appsync/utils/lib/resolver-return-types";
import { PlayerSheet, UpdatePlayerSheetInput } from "../../../appsync/graphql";
import { DDBPrefixGame, DDBPrefixPlayer } from "../../lib/constants";
import { PlayerSheet, UpdatePlayerInput } from "../../../appsync/graphql";
import { DDBPrefixGame, DDBPrefixPlayer, TypeShip } from "../../lib/constants";

export function request(
context: Context<{ input: UpdatePlayerSheetInput }>,
context: Context<{ input: UpdatePlayerInput }>,
): 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 (context.arguments.input.userId != identity.sub) {
util.error("Unauthorized: User ID does not match." as string);
}
if (!identity?.sub) util.unauthorized();

const input = context.arguments.input;
const timestamp = util.time.nowISO8601();
const sk = DDBPrefixPlayer + "#" + identity.sub;
const sk = DDBPrefixPlayer + "#" + input.userId;

return {
operation: "UpdateItem",
Expand All @@ -30,12 +21,14 @@ export function request(
SK: sk,
}),
condition: {
expression: "#SK = :SK",
expression: "#userId = :userId OR #type = :type",
expressionNames: {
"#SK": "SK",
"#userId": "userId",
"#type": "type",
},
expressionValues: util.dynamodb.toMapValues({
":SK": sk,
":userId": identity.sub,
":type": TypeShip,
}),
},
update: {
Expand All @@ -55,6 +48,8 @@ export function request(

export function response(context: Context): PlayerSheet | null {
if (context.error) {
if (context.error.type === "DynamoDB:ConditionalCheckFailedException")
util.unauthorized();
util.error(context.error.message, context.error.type, context.result);
}
return context.result;
Expand Down
4 changes: 2 additions & 2 deletions graphql/lib/dataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
Game,
PlayerSheet,
SheetSection,
SubscriptionUpdatedPlayerSheetArgs,
SubscriptionUpdatedPlayerArgs,
SubscriptionUpdatedSectionArgs,
} from "../../appsync/graphql";

Expand All @@ -18,7 +18,7 @@ export type DataSheetSection = SheetSection;
export type Data = DataGame | DataPlayerSheet | DataSheetSection;

export type SubscriptionGenericArgs =
| SubscriptionUpdatedPlayerSheetArgs
| SubscriptionUpdatedPlayerArgs
| SubscriptionUpdatedSectionArgs;

export type Empty = Record<string, never>;
Loading

0 comments on commit 89f5136

Please sign in to comment.