-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can add and edit your sheet sections (#108)
- Loading branch information
1 parent
016df0b
commit e8e7cba
Showing
25 changed files
with
292 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
60 changes: 60 additions & 0 deletions
60
graphql/function/fnCheckPlayerSheetAccess/checkPlayerSheetAccess.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { util, Context, AppSyncIdentityCognito } from "@aws-appsync/utils"; | ||
import type { DynamoDBGetItemRequest } from "@aws-appsync/utils/lib/resolver-return-types"; | ||
import type { DataPlayerSheet } from "../../lib/dataTypes"; | ||
import type { MutationCreateSectionArgs } from "../../../appsync/graphql"; | ||
|
||
export function request( | ||
context: Context<MutationCreateSectionArgs>, | ||
): DynamoDBGetItemRequest { | ||
if (!context.identity) { | ||
util.error("Unauthorized: Identity information is missing." as string); | ||
} | ||
|
||
const identity = context.identity as AppSyncIdentityCognito; | ||
if (!identity.sub) { | ||
util.error("Unauthorized: User ID is missing." as string); | ||
} | ||
|
||
const id = context.arguments.input.gameId; | ||
const key = { | ||
PK: "GAME#" + id, | ||
SK: "PLAYER#" + identity.sub, | ||
}; | ||
|
||
return { | ||
operation: "GetItem", | ||
key: util.dynamodb.toMapValues(key), | ||
}; | ||
} | ||
|
||
type ResponseContext = Context< | ||
MutationCreateSectionArgs, | ||
Record<string, unknown>, | ||
undefined, | ||
undefined, | ||
DataPlayerSheet | ||
>; | ||
|
||
export function response( | ||
context: ResponseContext, | ||
): DataPlayerSheet | undefined { | ||
if (context.error) { | ||
util.appendError(context.error.message, context.error.type, context.result); | ||
return; | ||
} | ||
|
||
const identity = context.identity as AppSyncIdentityCognito; | ||
if (!identity.sub) { | ||
util.appendError("Unauthorized: User ID is missing." as string); | ||
return; | ||
} | ||
|
||
if (identity.sub != context.result.userId) { | ||
util.appendError( | ||
"Unauthorized: User does not have access to the player sheet." as string, | ||
); | ||
return; | ||
} | ||
|
||
return context.result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { util, Context, AppSyncIdentityCognito } from "@aws-appsync/utils"; | ||
import type { | ||
DynamoDBPutItemRequest, | ||
PutItemInputAttributeMap, | ||
} from "@aws-appsync/utils/lib/resolver-return-types"; | ||
import { Game, CreateSectionInput } from "../../../appsync/graphql"; | ||
import { TypeSection } from "../../lib/constants"; | ||
|
||
export function request( | ||
context: Context<{ input: CreateSectionInput }>, | ||
): DynamoDBPutItemRequest { | ||
if (!context.identity) { | ||
util.error("Unauthorized: Identity information is missing." as string); | ||
} | ||
|
||
const identity = context.identity as AppSyncIdentityCognito; | ||
if (!identity.sub) { | ||
util.error("Unauthorized: User ID is missing." as string); | ||
} | ||
|
||
const input = context.arguments.input; | ||
const sectionId = util.autoId(); | ||
const timestamp = util.time.nowISO8601(); | ||
|
||
return { | ||
operation: "PutItem", | ||
key: util.dynamodb.toMapValues({ | ||
PK: "GAME#" + input.gameId, | ||
SK: TypeSection + "#" + sectionId, | ||
}), | ||
attributeValues: util.dynamodb.toMapValues({ | ||
gameId: input.gameId, | ||
userId: identity.sub, | ||
sectionId: sectionId, | ||
sectionName: input.sectionName, | ||
sectionType: input.sectionType, | ||
content: input.content, | ||
createdAt: timestamp, | ||
updatedAt: timestamp, | ||
type: TypeSection, | ||
}) as PutItemInputAttributeMap, | ||
}; | ||
} | ||
|
||
export function response(context: Context): Game | null { | ||
if (context.error) { | ||
util.appendError(context.error.message, context.error.type, context.result); | ||
return null; | ||
} | ||
return context.result; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { util, Context, AppSyncIdentityCognito } from "@aws-appsync/utils"; | ||
import type { DynamoDBUpdateItemRequest } from "@aws-appsync/utils/lib/resolver-return-types"; | ||
import { SheetSection, UpdateSectionInput } from "../../../appsync/graphql"; | ||
import { TypeSection } from "../../lib/constants"; | ||
|
||
export function request( | ||
context: Context<{ input: UpdateSectionInput }>, | ||
): DynamoDBUpdateItemRequest { | ||
if (!context.identity) { | ||
util.error("Unauthorized: Identity information is missing." as string); | ||
} | ||
|
||
const identity = context.identity as AppSyncIdentityCognito; | ||
if (!identity.sub) { | ||
util.error("Unauthorized: User ID is missing." as string); | ||
} | ||
|
||
const input = context.arguments.input; | ||
const timestamp = util.time.nowISO8601(); | ||
const sk = TypeSection + "#" + input.sectionId; | ||
|
||
return { | ||
operation: "UpdateItem", | ||
key: util.dynamodb.toMapValues({ | ||
PK: "GAME#" + input.gameId, | ||
SK: sk, | ||
}), | ||
condition: { | ||
expression: "#SK = :SK AND #userId = :userId", | ||
expressionNames: { | ||
"#SK": "SK", | ||
"#userId": "userId", | ||
}, | ||
expressionValues: util.dynamodb.toMapValues({ | ||
":SK": sk, | ||
":userId": identity.sub, | ||
}), | ||
}, | ||
update: { | ||
expression: | ||
"SET #sectionName = :sectionName, #content = :content, #updatedAt = :updatedAt", | ||
expressionNames: { | ||
"#updatedAt": "updatedAt", | ||
"#content": "content", | ||
"#sectionName": "sectionName", | ||
}, | ||
expressionValues: util.dynamodb.toMapValues({ | ||
":updatedAt": timestamp, | ||
":content": input.content, | ||
":sectionName": input.sectionName, | ||
}), | ||
}, | ||
}; | ||
} | ||
|
||
export function response(context: Context): SheetSection | null { | ||
if (context.error) { | ||
util.appendError(context.error.message, context.error.type, context.result); | ||
return null; | ||
} | ||
return context.result; | ||
} |
File renamed without changes.
Oops, something went wrong.