Skip to content

Commit

Permalink
fix: response of api
Browse files Browse the repository at this point in the history
  • Loading branch information
yuukiok committed Oct 14, 2024
1 parent f61aec0 commit d6f4f1c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 2 additions & 4 deletions packages/cdk/lambda/createUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ export const handler = async (
event.requestContext.authorizer!.claims['cognito:username'];
const title = req.title;
const promptTemplate = req.promptTemplate;
const useCaseId = await createUseCase(userId, title, promptTemplate);
const useCaseIdRes = await createUseCase(userId, title, promptTemplate);

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
useCaseId,
}),
body: JSON.stringify(useCaseIdRes),
};
} catch (error) {
console.log(error);
Expand Down
4 changes: 2 additions & 2 deletions packages/cdk/lambda/listFavoriteUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export const handler = async (
try {
const userId: string =
event.requestContext.authorizer!.claims['cognito:username'];
const favoriteUseCases = await listFavoriteUseCases(userId);
const favoriteUseCasesRes = await listFavoriteUseCases(userId);

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({ favoriteUseCases }),
body: JSON.stringify(favoriteUseCasesRes),
};
} catch (error) {
console.log(error);
Expand Down
4 changes: 2 additions & 2 deletions packages/cdk/lambda/listUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export const handler = async (
try {
const userId: string =
event.requestContext.authorizer!.claims['cognito:username'];
const useCases = await listUseCases(userId);
const useCasesRes = await listUseCases(userId);

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({ useCases }),
body: JSON.stringify(useCasesRes),
};
} catch (error) {
console.log(error);
Expand Down
4 changes: 1 addition & 3 deletions packages/cdk/lambda/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,7 @@ export const toggleFavorite = async (
},
})
);
return {
isFavorite: false,
};
return { isFavorite: false };
} else {
await dynamoDbDocument.send(
new PutCommand({
Expand Down
10 changes: 7 additions & 3 deletions packages/cdk/lambda/toggleFavorite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { ToggleFavoriteRequest } from 'generative-ai-use-cases-jp';
import { IsFavorite, ToggleFavoriteRequest } from 'generative-ai-use-cases-jp';
import { toggleFavorite } from './repository';

export const handler = async (
Expand All @@ -12,15 +12,19 @@ export const handler = async (
const req: ToggleFavoriteRequest = JSON.parse(event.body!);
const ownerUserId = req.ownerUserId;

await toggleFavorite(userId, useCaseId, ownerUserId);
const isFavoriteRes: IsFavorite = await toggleFavorite(
userId,
useCaseId,
ownerUserId
);

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: '',
body: JSON.stringify(isFavoriteRes),
};
} catch (error) {
console.log(error);
Expand Down
4 changes: 2 additions & 2 deletions packages/cdk/lambda/toggleShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const handler = async (
}

const hasShared = useCase.hasShared;
const newHasShared: HasShared = await toggleShared(
const newHasSharedRes: HasShared = await toggleShared(
userId,
useCaseId,
hasShared
Expand All @@ -36,7 +36,7 @@ export const handler = async (
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({ newHasShared }),
body: JSON.stringify(newHasSharedRes),
};
} catch (error) {
console.log(error);
Expand Down

0 comments on commit d6f4f1c

Please sign in to comment.