Skip to content

Commit

Permalink
Merge pull request #47 from Code-4-Community/dl-get-site-IDs-per-user
Browse files Browse the repository at this point in the history
Dl get site Ids per user
  • Loading branch information
dli85 authored Nov 4, 2024
2 parents b5ca547 + 1cc80b0 commit 0544cff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ export class UserController {
return this.userService.getUser(userId);
}


@Get(":id/sites")
public async getUserSites(@Param("id") userId?: number): Promise<any> {
return this.userService.getUserTables(userId);
}


}
18 changes: 17 additions & 1 deletion apps/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ export class UserService {
}


public async getUserTables(userId: number): Promise<Array<number>> {
try {
const key = { 'userId' : {N: userId.toString()}};
const data = await this.dynamoDbService.getItem(this.tableName, key);
if (!data) {
throw new Error(`No user found with id: ${userId}`);
}
console.log(data);
const siteIds = data["siteIds"].L.map(item => Number(item.N));
return siteIds;
}
catch(e) {
throw new Error(`Error fetching data for user with id: ${userId}: ${e.message}`);
}
}


/**
* Maps a user's data from DynamoDB to a UserModel object.
* @param objectId the user's id
Expand Down Expand Up @@ -64,5 +81,4 @@ export class UserService {
}



}

0 comments on commit 0544cff

Please sign in to comment.