Skip to content

Commit

Permalink
feat: add client api of findDeckListByUserId api (#105)
Browse files Browse the repository at this point in the history
* feat: add client api of getDeckListByUserId api

* refactor: update the return type of getDeckListByUserId api
  • Loading branch information
pjw5521 authored Jul 29, 2023
1 parent 8f7640b commit 270a7cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const card = JSON_APIS({
// Todo : change to session
createCard: ({ createCardDto }: { createCardDto: CreateCardDto }) =>
client.public.post<{ result: boolean }>('cards', createCardDto),
// get card by id
/* get List of Cards in deck: Get card information by deck id */
// Todo : change to session
getCards: ({ id }: { id: string }) => client.public.get<{ result: Card[] | null }>(`decks/id=${id}/cards`),
getCards: ({ deckId }: { deckId: string }) =>
client.public.get<{ result: Card[] | null }>(`decks/id=${deckId}/cards`),
/* delete card by id */
// Todo : change to session
deleteCard: ({ id }: { id: string }) => client.public.delete<{ result: boolean }>(`cards/id=${id}`),
Expand All @@ -40,9 +41,12 @@ const deck = JSON_APIS({
client.public.post<{ deck_id: string }>('decks', createDeckDto),
/* get Deck: Get card information by deck id */
// Todo : change to session
getDeck: ({ id }: { id: string }) => client.public.get<{ result: Deck | null }>(`decks/id=${id}`),
/* get List of Cards in deck: Get card information by deck id */
getDeck: ({ deckId }: { deckId: string }) => client.public.get<{ result: Deck | null }>(`decks/id=${deckId}`),
/* Get all deck info */
getAllDeck: () => client.public.get<{ result: Deck[] }>(`decks`),
/* Get deck list of user id */
getDeckListByUserId: ({ userId }: { userId: string }) =>
client.session.get<{ result: Deck[] | null }>(`decks/user/${userId}`),
});

export const api = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class DeckController {
}

@Get('/user/:userId')
async findByUserId(@Param('userId') userId: string): Promise<{ result: Deck[] | null }> {
async findByUserId(@Param('userId') userId: string): Promise<{ result: Deck[] | [] }> {
const result = await this.deckService.findDeckListByUserId(userId);
return { result: result };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/service-backend/src/modules/deck/DeckService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DeckService {
return await this.deckRepository.findAll();
}

async findDeckListByUserId(userId: string): Promise<Deck[]> {
async findDeckListByUserId(userId: string): Promise<Deck[] | []> {
return await this.deckRepository.findByUserId(userId);
}

Expand Down

0 comments on commit 270a7cf

Please sign in to comment.