@aurora-interactive/sensei-productivity 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/commonjs/funcs/categories-create.d.ts +1 -1
- package/dist/commonjs/funcs/categories-create.d.ts.map +1 -1
- package/dist/commonjs/funcs/categories-create.js +3 -2
- package/dist/commonjs/funcs/categories-create.js.map +1 -1
- package/dist/commonjs/funcs/categories-delete.js +2 -2
- package/dist/commonjs/funcs/categories-delete.js.map +1 -1
- package/dist/commonjs/funcs/categories-get-all.d.ts +1 -1
- package/dist/commonjs/funcs/categories-get-all.d.ts.map +1 -1
- package/dist/commonjs/funcs/categories-get-all.js +3 -2
- package/dist/commonjs/funcs/categories-get-all.js.map +1 -1
- package/dist/commonjs/funcs/categories-update.d.ts +1 -1
- package/dist/commonjs/funcs/categories-update.d.ts.map +1 -1
- package/dist/commonjs/funcs/categories-update.js +3 -2
- package/dist/commonjs/funcs/categories-update.js.map +1 -1
- package/dist/commonjs/funcs/schools-get-all.js +2 -2
- package/dist/commonjs/funcs/schools-get-all.js.map +1 -1
- package/dist/commonjs/funcs/schools-get.d.ts +1 -1
- package/dist/commonjs/funcs/schools-get.d.ts.map +1 -1
- package/dist/commonjs/funcs/schools-get.js +3 -2
- package/dist/commonjs/funcs/schools-get.js.map +1 -1
- package/dist/commonjs/funcs/users-activities-create.d.ts +1 -1
- package/dist/commonjs/funcs/users-activities-create.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-activities-create.js +3 -2
- package/dist/commonjs/funcs/users-activities-create.js.map +1 -1
- package/dist/commonjs/funcs/users-activities-delete.js +2 -2
- package/dist/commonjs/funcs/users-activities-delete.js.map +1 -1
- package/dist/commonjs/funcs/users-activities-get-all-of-user.d.ts +1 -1
- package/dist/commonjs/funcs/users-activities-get-all-of-user.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-activities-get-all-of-user.js +3 -2
- package/dist/commonjs/funcs/users-activities-get-all-of-user.js.map +1 -1
- package/dist/commonjs/funcs/users-activities-get.d.ts +1 -1
- package/dist/commonjs/funcs/users-activities-get.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-activities-get.js +3 -2
- package/dist/commonjs/funcs/users-activities-get.js.map +1 -1
- package/dist/commonjs/funcs/users-activities-me.d.ts +1 -1
- package/dist/commonjs/funcs/users-activities-me.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-activities-me.js +3 -2
- package/dist/commonjs/funcs/users-activities-me.js.map +1 -1
- package/dist/commonjs/funcs/users-activities-update.d.ts +1 -1
- package/dist/commonjs/funcs/users-activities-update.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-activities-update.js +3 -2
- package/dist/commonjs/funcs/users-activities-update.js.map +1 -1
- package/dist/commonjs/funcs/users-delete.js +2 -2
- package/dist/commonjs/funcs/users-delete.js.map +1 -1
- package/dist/commonjs/funcs/users-friends-accept.d.ts +14 -0
- package/dist/commonjs/funcs/users-friends-accept.d.ts.map +1 -0
- package/dist/commonjs/funcs/users-friends-accept.js +127 -0
- package/dist/commonjs/funcs/users-friends-accept.js.map +1 -0
- package/dist/commonjs/funcs/users-friends-list.d.ts +14 -0
- package/dist/commonjs/funcs/users-friends-list.d.ts.map +1 -0
- package/dist/commonjs/funcs/users-friends-list.js +128 -0
- package/dist/commonjs/funcs/users-friends-list.js.map +1 -0
- package/dist/commonjs/funcs/users-friends-pending.d.ts +14 -0
- package/dist/commonjs/funcs/users-friends-pending.d.ts.map +1 -0
- package/dist/commonjs/funcs/users-friends-pending.js +113 -0
- package/dist/commonjs/funcs/users-friends-pending.js.map +1 -0
- package/dist/commonjs/funcs/users-friends-reject.d.ts +14 -0
- package/dist/commonjs/funcs/users-friends-reject.d.ts.map +1 -0
- package/dist/commonjs/funcs/users-friends-reject.js +127 -0
- package/dist/commonjs/funcs/users-friends-reject.js.map +1 -0
- package/dist/commonjs/funcs/users-friends-remove.d.ts +14 -0
- package/dist/commonjs/funcs/users-friends-remove.d.ts.map +1 -0
- package/dist/commonjs/funcs/users-friends-remove.js +127 -0
- package/dist/commonjs/funcs/users-friends-remove.js.map +1 -0
- package/dist/commonjs/funcs/users-friends-send-request.d.ts +14 -0
- package/dist/commonjs/funcs/users-friends-send-request.d.ts.map +1 -0
- package/dist/commonjs/funcs/users-friends-send-request.js +127 -0
- package/dist/commonjs/funcs/users-friends-send-request.js.map +1 -0
- package/dist/commonjs/funcs/users-get.d.ts +1 -1
- package/dist/commonjs/funcs/users-get.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-get.js +3 -2
- package/dist/commonjs/funcs/users-get.js.map +1 -1
- package/dist/commonjs/funcs/users-login.d.ts +1 -1
- package/dist/commonjs/funcs/users-login.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-login.js +3 -2
- package/dist/commonjs/funcs/users-login.js.map +1 -1
- package/dist/commonjs/funcs/users-me.d.ts +1 -1
- package/dist/commonjs/funcs/users-me.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-me.js +3 -2
- package/dist/commonjs/funcs/users-me.js.map +1 -1
- package/dist/commonjs/funcs/users-posts-delete.js +2 -2
- package/dist/commonjs/funcs/users-posts-delete.js.map +1 -1
- package/dist/commonjs/funcs/users-posts-feed.d.ts +1 -1
- package/dist/commonjs/funcs/users-posts-feed.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-posts-feed.js +3 -2
- package/dist/commonjs/funcs/users-posts-feed.js.map +1 -1
- package/dist/commonjs/funcs/users-posts-get-by-post-id.d.ts +1 -1
- package/dist/commonjs/funcs/users-posts-get-by-post-id.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-posts-get-by-post-id.js +3 -2
- package/dist/commonjs/funcs/users-posts-get-by-post-id.js.map +1 -1
- package/dist/commonjs/funcs/users-posts-get-by-user-id.d.ts +1 -1
- package/dist/commonjs/funcs/users-posts-get-by-user-id.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-posts-get-by-user-id.js +3 -2
- package/dist/commonjs/funcs/users-posts-get-by-user-id.js.map +1 -1
- package/dist/commonjs/funcs/users-posts-update.d.ts +1 -1
- package/dist/commonjs/funcs/users-posts-update.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-posts-update.js +3 -2
- package/dist/commonjs/funcs/users-posts-update.js.map +1 -1
- package/dist/commonjs/funcs/users-signup.d.ts +1 -1
- package/dist/commonjs/funcs/users-signup.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-signup.js +3 -2
- package/dist/commonjs/funcs/users-signup.js.map +1 -1
- package/dist/commonjs/funcs/users-update.d.ts +1 -1
- package/dist/commonjs/funcs/users-update.d.ts.map +1 -1
- package/dist/commonjs/funcs/users-update.js +3 -2
- package/dist/commonjs/funcs/users-update.js.map +1 -1
- package/dist/commonjs/lib/config.d.ts +3 -3
- package/dist/commonjs/lib/config.js +3 -3
- package/dist/commonjs/models/operations/accept-friend-request.d.ts +15 -0
- package/dist/commonjs/models/operations/accept-friend-request.d.ts.map +1 -0
- package/dist/commonjs/models/operations/accept-friend-request.js +49 -0
- package/dist/commonjs/models/operations/accept-friend-request.js.map +1 -0
- package/dist/commonjs/models/operations/index.d.ts +6 -0
- package/dist/commonjs/models/operations/index.d.ts.map +1 -1
- package/dist/commonjs/models/operations/index.js +6 -0
- package/dist/commonjs/models/operations/index.js.map +1 -1
- package/dist/commonjs/models/operations/list-friends.d.ts +26 -0
- package/dist/commonjs/models/operations/list-friends.d.ts.map +1 -0
- package/dist/commonjs/models/operations/list-friends.js +65 -0
- package/dist/commonjs/models/operations/list-friends.js.map +1 -0
- package/dist/commonjs/models/operations/pending-friend-requests.d.ts +16 -0
- package/dist/commonjs/models/operations/pending-friend-requests.d.ts.map +1 -0
- package/dist/commonjs/models/operations/pending-friend-requests.js +57 -0
- package/dist/commonjs/models/operations/pending-friend-requests.js.map +1 -0
- package/dist/commonjs/models/operations/reject-friend-request.d.ts +15 -0
- package/dist/commonjs/models/operations/reject-friend-request.d.ts.map +1 -0
- package/dist/commonjs/models/operations/reject-friend-request.js +49 -0
- package/dist/commonjs/models/operations/reject-friend-request.js.map +1 -0
- package/dist/commonjs/models/operations/remove-friend.d.ts +12 -0
- package/dist/commonjs/models/operations/remove-friend.d.ts.map +1 -0
- package/dist/commonjs/models/operations/remove-friend.js +49 -0
- package/dist/commonjs/models/operations/remove-friend.js.map +1 -0
- package/dist/commonjs/models/operations/send-friend-request.d.ts +12 -0
- package/dist/commonjs/models/operations/send-friend-request.d.ts.map +1 -0
- package/dist/commonjs/models/operations/send-friend-request.js +49 -0
- package/dist/commonjs/models/operations/send-friend-request.js.map +1 -0
- package/dist/commonjs/sdk/activities.d.ts +5 -5
- package/dist/commonjs/sdk/activities.d.ts.map +1 -1
- package/dist/commonjs/sdk/categories.d.ts +3 -3
- package/dist/commonjs/sdk/categories.d.ts.map +1 -1
- package/dist/commonjs/sdk/friends.d.ts +29 -0
- package/dist/commonjs/sdk/friends.d.ts.map +1 -0
- package/dist/commonjs/sdk/friends.js +54 -0
- package/dist/commonjs/sdk/friends.js.map +1 -0
- package/dist/commonjs/sdk/posts.d.ts +4 -4
- package/dist/commonjs/sdk/posts.d.ts.map +1 -1
- package/dist/commonjs/sdk/schools.d.ts +1 -1
- package/dist/commonjs/sdk/schools.d.ts.map +1 -1
- package/dist/commonjs/sdk/users.d.ts +8 -5
- package/dist/commonjs/sdk/users.d.ts.map +1 -1
- package/dist/commonjs/sdk/users.js +4 -0
- package/dist/commonjs/sdk/users.js.map +1 -1
- package/dist/esm/funcs/categories-create.d.ts +1 -1
- package/dist/esm/funcs/categories-create.d.ts.map +1 -1
- package/dist/esm/funcs/categories-create.js +3 -2
- package/dist/esm/funcs/categories-create.js.map +1 -1
- package/dist/esm/funcs/categories-delete.js +2 -2
- package/dist/esm/funcs/categories-delete.js.map +1 -1
- package/dist/esm/funcs/categories-get-all.d.ts +1 -1
- package/dist/esm/funcs/categories-get-all.d.ts.map +1 -1
- package/dist/esm/funcs/categories-get-all.js +3 -2
- package/dist/esm/funcs/categories-get-all.js.map +1 -1
- package/dist/esm/funcs/categories-update.d.ts +1 -1
- package/dist/esm/funcs/categories-update.d.ts.map +1 -1
- package/dist/esm/funcs/categories-update.js +3 -2
- package/dist/esm/funcs/categories-update.js.map +1 -1
- package/dist/esm/funcs/schools-get-all.js +2 -2
- package/dist/esm/funcs/schools-get-all.js.map +1 -1
- package/dist/esm/funcs/schools-get.d.ts +1 -1
- package/dist/esm/funcs/schools-get.d.ts.map +1 -1
- package/dist/esm/funcs/schools-get.js +3 -2
- package/dist/esm/funcs/schools-get.js.map +1 -1
- package/dist/esm/funcs/users-activities-create.d.ts +1 -1
- package/dist/esm/funcs/users-activities-create.d.ts.map +1 -1
- package/dist/esm/funcs/users-activities-create.js +3 -2
- package/dist/esm/funcs/users-activities-create.js.map +1 -1
- package/dist/esm/funcs/users-activities-delete.js +2 -2
- package/dist/esm/funcs/users-activities-delete.js.map +1 -1
- package/dist/esm/funcs/users-activities-get-all-of-user.d.ts +1 -1
- package/dist/esm/funcs/users-activities-get-all-of-user.d.ts.map +1 -1
- package/dist/esm/funcs/users-activities-get-all-of-user.js +3 -2
- package/dist/esm/funcs/users-activities-get-all-of-user.js.map +1 -1
- package/dist/esm/funcs/users-activities-get.d.ts +1 -1
- package/dist/esm/funcs/users-activities-get.d.ts.map +1 -1
- package/dist/esm/funcs/users-activities-get.js +3 -2
- package/dist/esm/funcs/users-activities-get.js.map +1 -1
- package/dist/esm/funcs/users-activities-me.d.ts +1 -1
- package/dist/esm/funcs/users-activities-me.d.ts.map +1 -1
- package/dist/esm/funcs/users-activities-me.js +3 -2
- package/dist/esm/funcs/users-activities-me.js.map +1 -1
- package/dist/esm/funcs/users-activities-update.d.ts +1 -1
- package/dist/esm/funcs/users-activities-update.d.ts.map +1 -1
- package/dist/esm/funcs/users-activities-update.js +3 -2
- package/dist/esm/funcs/users-activities-update.js.map +1 -1
- package/dist/esm/funcs/users-delete.js +2 -2
- package/dist/esm/funcs/users-delete.js.map +1 -1
- package/dist/esm/funcs/users-friends-accept.d.ts +14 -0
- package/dist/esm/funcs/users-friends-accept.d.ts.map +1 -0
- package/dist/esm/funcs/users-friends-accept.js +91 -0
- package/dist/esm/funcs/users-friends-accept.js.map +1 -0
- package/dist/esm/funcs/users-friends-list.d.ts +14 -0
- package/dist/esm/funcs/users-friends-list.d.ts.map +1 -0
- package/dist/esm/funcs/users-friends-list.js +92 -0
- package/dist/esm/funcs/users-friends-list.js.map +1 -0
- package/dist/esm/funcs/users-friends-pending.d.ts +14 -0
- package/dist/esm/funcs/users-friends-pending.d.ts.map +1 -0
- package/dist/esm/funcs/users-friends-pending.js +77 -0
- package/dist/esm/funcs/users-friends-pending.js.map +1 -0
- package/dist/esm/funcs/users-friends-reject.d.ts +14 -0
- package/dist/esm/funcs/users-friends-reject.d.ts.map +1 -0
- package/dist/esm/funcs/users-friends-reject.js +91 -0
- package/dist/esm/funcs/users-friends-reject.js.map +1 -0
- package/dist/esm/funcs/users-friends-remove.d.ts +14 -0
- package/dist/esm/funcs/users-friends-remove.d.ts.map +1 -0
- package/dist/esm/funcs/users-friends-remove.js +91 -0
- package/dist/esm/funcs/users-friends-remove.js.map +1 -0
- package/dist/esm/funcs/users-friends-send-request.d.ts +14 -0
- package/dist/esm/funcs/users-friends-send-request.d.ts.map +1 -0
- package/dist/esm/funcs/users-friends-send-request.js +91 -0
- package/dist/esm/funcs/users-friends-send-request.js.map +1 -0
- package/dist/esm/funcs/users-get.d.ts +1 -1
- package/dist/esm/funcs/users-get.d.ts.map +1 -1
- package/dist/esm/funcs/users-get.js +3 -2
- package/dist/esm/funcs/users-get.js.map +1 -1
- package/dist/esm/funcs/users-login.d.ts +1 -1
- package/dist/esm/funcs/users-login.d.ts.map +1 -1
- package/dist/esm/funcs/users-login.js +3 -2
- package/dist/esm/funcs/users-login.js.map +1 -1
- package/dist/esm/funcs/users-me.d.ts +1 -1
- package/dist/esm/funcs/users-me.d.ts.map +1 -1
- package/dist/esm/funcs/users-me.js +3 -2
- package/dist/esm/funcs/users-me.js.map +1 -1
- package/dist/esm/funcs/users-posts-delete.js +2 -2
- package/dist/esm/funcs/users-posts-delete.js.map +1 -1
- package/dist/esm/funcs/users-posts-feed.d.ts +1 -1
- package/dist/esm/funcs/users-posts-feed.d.ts.map +1 -1
- package/dist/esm/funcs/users-posts-feed.js +3 -2
- package/dist/esm/funcs/users-posts-feed.js.map +1 -1
- package/dist/esm/funcs/users-posts-get-by-post-id.d.ts +1 -1
- package/dist/esm/funcs/users-posts-get-by-post-id.d.ts.map +1 -1
- package/dist/esm/funcs/users-posts-get-by-post-id.js +3 -2
- package/dist/esm/funcs/users-posts-get-by-post-id.js.map +1 -1
- package/dist/esm/funcs/users-posts-get-by-user-id.d.ts +1 -1
- package/dist/esm/funcs/users-posts-get-by-user-id.d.ts.map +1 -1
- package/dist/esm/funcs/users-posts-get-by-user-id.js +3 -2
- package/dist/esm/funcs/users-posts-get-by-user-id.js.map +1 -1
- package/dist/esm/funcs/users-posts-update.d.ts +1 -1
- package/dist/esm/funcs/users-posts-update.d.ts.map +1 -1
- package/dist/esm/funcs/users-posts-update.js +3 -2
- package/dist/esm/funcs/users-posts-update.js.map +1 -1
- package/dist/esm/funcs/users-signup.d.ts +1 -1
- package/dist/esm/funcs/users-signup.d.ts.map +1 -1
- package/dist/esm/funcs/users-signup.js +3 -2
- package/dist/esm/funcs/users-signup.js.map +1 -1
- package/dist/esm/funcs/users-update.d.ts +1 -1
- package/dist/esm/funcs/users-update.d.ts.map +1 -1
- package/dist/esm/funcs/users-update.js +3 -2
- package/dist/esm/funcs/users-update.js.map +1 -1
- package/dist/esm/lib/config.d.ts +3 -3
- package/dist/esm/lib/config.js +3 -3
- package/dist/esm/models/operations/accept-friend-request.d.ts +15 -0
- package/dist/esm/models/operations/accept-friend-request.d.ts.map +1 -0
- package/dist/esm/models/operations/accept-friend-request.js +12 -0
- package/dist/esm/models/operations/accept-friend-request.js.map +1 -0
- package/dist/esm/models/operations/index.d.ts +6 -0
- package/dist/esm/models/operations/index.d.ts.map +1 -1
- package/dist/esm/models/operations/index.js +6 -0
- package/dist/esm/models/operations/index.js.map +1 -1
- package/dist/esm/models/operations/list-friends.d.ts +26 -0
- package/dist/esm/models/operations/list-friends.d.ts.map +1 -0
- package/dist/esm/models/operations/list-friends.js +27 -0
- package/dist/esm/models/operations/list-friends.js.map +1 -0
- package/dist/esm/models/operations/pending-friend-requests.d.ts +16 -0
- package/dist/esm/models/operations/pending-friend-requests.d.ts.map +1 -0
- package/dist/esm/models/operations/pending-friend-requests.js +20 -0
- package/dist/esm/models/operations/pending-friend-requests.js.map +1 -0
- package/dist/esm/models/operations/reject-friend-request.d.ts +15 -0
- package/dist/esm/models/operations/reject-friend-request.d.ts.map +1 -0
- package/dist/esm/models/operations/reject-friend-request.js +12 -0
- package/dist/esm/models/operations/reject-friend-request.js.map +1 -0
- package/dist/esm/models/operations/remove-friend.d.ts +12 -0
- package/dist/esm/models/operations/remove-friend.d.ts.map +1 -0
- package/dist/esm/models/operations/remove-friend.js +12 -0
- package/dist/esm/models/operations/remove-friend.js.map +1 -0
- package/dist/esm/models/operations/send-friend-request.d.ts +12 -0
- package/dist/esm/models/operations/send-friend-request.d.ts.map +1 -0
- package/dist/esm/models/operations/send-friend-request.js +12 -0
- package/dist/esm/models/operations/send-friend-request.js.map +1 -0
- package/dist/esm/sdk/activities.d.ts +5 -5
- package/dist/esm/sdk/activities.d.ts.map +1 -1
- package/dist/esm/sdk/categories.d.ts +3 -3
- package/dist/esm/sdk/categories.d.ts.map +1 -1
- package/dist/esm/sdk/friends.d.ts +29 -0
- package/dist/esm/sdk/friends.d.ts.map +1 -0
- package/dist/esm/sdk/friends.js +50 -0
- package/dist/esm/sdk/friends.js.map +1 -0
- package/dist/esm/sdk/posts.d.ts +4 -4
- package/dist/esm/sdk/posts.d.ts.map +1 -1
- package/dist/esm/sdk/schools.d.ts +1 -1
- package/dist/esm/sdk/schools.d.ts.map +1 -1
- package/dist/esm/sdk/users.d.ts +8 -5
- package/dist/esm/sdk/users.d.ts.map +1 -1
- package/dist/esm/sdk/users.js +4 -0
- package/dist/esm/sdk/users.js.map +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/rest-api/cypress/e2e/friend-endpoints.cy.js +262 -0
- package/rest-api/cypress/e2e/{school-endpoints.cy.ts → school-endpoints.cy.js} +1 -1
- package/rest-api/cypress.config.ts +45 -2
- package/rest-api/index.js +8 -1
- package/rest-api/lib/users.js +7 -5
- package/rest-api/routes/FriendFunctions.js +266 -0
- package/rest-api/routes/UserActivityFunctions.js +1 -1
- package/src/funcs/categories-create.ts +14 -6
- package/src/funcs/categories-delete.ts +3 -2
- package/src/funcs/categories-get-all.ts +14 -6
- package/src/funcs/categories-update.ts +14 -6
- package/src/funcs/schools-get-all.ts +2 -2
- package/src/funcs/schools-get.ts +11 -6
- package/src/funcs/users-activities-create.ts +14 -6
- package/src/funcs/users-activities-delete.ts +3 -2
- package/src/funcs/users-activities-get-all-of-user.ts +18 -6
- package/src/funcs/users-activities-get.ts +14 -6
- package/src/funcs/users-activities-me.ts +14 -6
- package/src/funcs/users-activities-update.ts +14 -6
- package/src/funcs/users-delete.ts +3 -2
- package/src/funcs/users-friends-accept.ts +176 -0
- package/src/funcs/users-friends-list.ts +182 -0
- package/src/funcs/users-friends-pending.ts +162 -0
- package/src/funcs/users-friends-reject.ts +176 -0
- package/src/funcs/users-friends-remove.ts +175 -0
- package/src/funcs/users-friends-send-request.ts +176 -0
- package/src/funcs/users-get.ts +11 -6
- package/src/funcs/users-login.ts +11 -6
- package/src/funcs/users-me.ts +14 -6
- package/src/funcs/users-posts-delete.ts +3 -2
- package/src/funcs/users-posts-feed.ts +8 -6
- package/src/funcs/users-posts-get-by-post-id.ts +11 -6
- package/src/funcs/users-posts-get-by-user-id.ts +14 -6
- package/src/funcs/users-posts-update.ts +11 -6
- package/src/funcs/users-signup.ts +8 -6
- package/src/funcs/users-update.ts +11 -6
- package/src/lib/config.ts +3 -3
- package/src/models/operations/accept-friend-request.ts +33 -0
- package/src/models/operations/index.ts +6 -0
- package/src/models/operations/list-friends.ts +68 -0
- package/src/models/operations/pending-friend-requests.ts +43 -0
- package/src/models/operations/reject-friend-request.ts +33 -0
- package/src/models/operations/remove-friend.ts +30 -0
- package/src/models/operations/send-friend-request.ts +30 -0
- package/src/sdk/activities.ts +5 -5
- package/src/sdk/categories.ts +3 -3
- package/src/sdk/friends.ts +97 -0
- package/src/sdk/posts.ts +4 -4
- package/src/sdk/schools.ts +1 -1
- package/src/sdk/users.ts +11 -5
- /package/rest-api/cypress/e2e/{activity-post-endpoints.cy.ts → activity-post-endpoints.cy.js} +0 -0
- /package/rest-api/cypress/e2e/{category-endpoints.cy.ts → category-endpoints.cy.js} +0 -0
- /package/rest-api/cypress/e2e/{user-activity-endpoints.cy.ts → user-activity-endpoints.cy.js} +0 -0
- /package/rest-api/cypress/e2e/{user-endpoints.cy.ts → user-endpoints.cy.js} +0 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
describe('Friend Endpoints Unit Tests', () => {
|
|
2
|
+
beforeEach(() => {
|
|
3
|
+
cy.task('clearFriendRequestsTable');
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
// Friends list
|
|
7
|
+
it('Getting friends list by user ID should fail due to invalid access token', () => {
|
|
8
|
+
cy.task('prepAcceptedFriendRequests');
|
|
9
|
+
|
|
10
|
+
cy.request({
|
|
11
|
+
failOnStatusCode: false,
|
|
12
|
+
method: "get",
|
|
13
|
+
url: "users/2/friends",
|
|
14
|
+
headers: {
|
|
15
|
+
"Authorization": "Bearer invalidBearer"
|
|
16
|
+
}
|
|
17
|
+
}).then(response => {
|
|
18
|
+
expect(response.status).to.equal(401, "Getting friends list by user ID should have failed with HTTP 401; different code was found instead!");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Getting friends list by user ID should fail due to invalid user ID', () => {
|
|
23
|
+
cy.task('prepAcceptedFriendRequests');
|
|
24
|
+
|
|
25
|
+
cy.request({
|
|
26
|
+
failOnStatusCode: false,
|
|
27
|
+
method: "get",
|
|
28
|
+
url: "users/99/friends",
|
|
29
|
+
headers: {
|
|
30
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
31
|
+
}
|
|
32
|
+
}).then(response => {
|
|
33
|
+
expect(response.status).to.equal(404, "Getting friends list by user ID should have failed with HTTP 404; different code was found instead!");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('Getting friends list by user ID should succeed', () => {
|
|
38
|
+
cy.task('prepAcceptedFriendRequests');
|
|
39
|
+
|
|
40
|
+
cy.request({
|
|
41
|
+
method: "get",
|
|
42
|
+
url: "users/2/friends",
|
|
43
|
+
headers: {
|
|
44
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
45
|
+
}
|
|
46
|
+
}).then(response => {
|
|
47
|
+
expect(response.status).to.equal(200, "Getting friends list by user ID should have succeeded; got non-success code instead!");
|
|
48
|
+
expect(response.body).to.be.an("array");
|
|
49
|
+
expect(response.body.length).to.equal(1);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Pending friend requests
|
|
54
|
+
it('Getting pending friend requests should fail due to invalid access token', () => {
|
|
55
|
+
cy.task('prepPendingFriendRequests');
|
|
56
|
+
|
|
57
|
+
cy.request({
|
|
58
|
+
failOnStatusCode: false,
|
|
59
|
+
method: "get",
|
|
60
|
+
url: "users/friends/pending",
|
|
61
|
+
headers: {
|
|
62
|
+
"Authorization": "Bearer invalidBearer"
|
|
63
|
+
}
|
|
64
|
+
}).then(response => {
|
|
65
|
+
expect(response.status).to.equal(401, "Getting pending friend requests should have failed with HTTP 401; different code was found instead!");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('Getting pending friend requests should succeed', () => {
|
|
70
|
+
cy.task('prepPendingFriendRequests');
|
|
71
|
+
|
|
72
|
+
cy.request({
|
|
73
|
+
method: "get",
|
|
74
|
+
url: "users/friends/pending",
|
|
75
|
+
headers: {
|
|
76
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
77
|
+
}
|
|
78
|
+
}).then(response => {
|
|
79
|
+
expect(response.status).to.equal(200, "Getting pending friend requests should have succeeded; got non-success code instead!");
|
|
80
|
+
expect(response.body).to.be.an("array");
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Send friend request
|
|
85
|
+
it('Sending friend request should fail due to invalid bearer token', () => {
|
|
86
|
+
cy.request({
|
|
87
|
+
failOnStatusCode: false,
|
|
88
|
+
method: "post",
|
|
89
|
+
url: "users/3/friend-request",
|
|
90
|
+
headers: {
|
|
91
|
+
"Authorization": "Bearer invalidBearer"
|
|
92
|
+
}
|
|
93
|
+
}).then(response => {
|
|
94
|
+
expect(response.status).to.equal(401, "Sending friend request should have failed with HTTP 404; different code was found instead!");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('Sending friend request should fail due to invalid user ID', () => {
|
|
99
|
+
cy.request({
|
|
100
|
+
failOnStatusCode: false,
|
|
101
|
+
method: "post",
|
|
102
|
+
url: "users/99/friend-request",
|
|
103
|
+
headers: {
|
|
104
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
105
|
+
}
|
|
106
|
+
}).then(response => {
|
|
107
|
+
expect(response.status).to.equal(404, "Sending friend request should have failed with HTTP 404; different code was found instead!");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('Sending friend request should succeed', () => {
|
|
112
|
+
cy.request({
|
|
113
|
+
method: "post",
|
|
114
|
+
url: "users/3/friend-request",
|
|
115
|
+
headers: {
|
|
116
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
117
|
+
}
|
|
118
|
+
}).then(response => {
|
|
119
|
+
expect(response.status).to.equal(201, "Sending friend request should have succeeded; got non-success code instead!");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Accept pending friend request
|
|
124
|
+
// in this group; using bearer of second test user because accepting is from
|
|
125
|
+
// the requested user's perspective
|
|
126
|
+
it('Accepting friend request should fail due to invalid bearer token', () => {
|
|
127
|
+
cy.task('prepPendingFriendRequests');
|
|
128
|
+
|
|
129
|
+
cy.request({
|
|
130
|
+
failOnStatusCode: false,
|
|
131
|
+
method: "patch",
|
|
132
|
+
url: "friend-requests/2/accept",
|
|
133
|
+
headers: {
|
|
134
|
+
"Authorization": "Bearer invalidBearer"
|
|
135
|
+
}
|
|
136
|
+
}).then(response => {
|
|
137
|
+
expect(response.status).to.equal(401, "Accepting friend request should have failed with HTTP 401; different code was found instead!");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('Accepting friend request should fail due to invalid user ID', () => {
|
|
142
|
+
cy.task('prepPendingFriendRequests');
|
|
143
|
+
|
|
144
|
+
cy.request({
|
|
145
|
+
failOnStatusCode: false,
|
|
146
|
+
method: "patch",
|
|
147
|
+
url: "friend-requests/99/accept",
|
|
148
|
+
headers: {
|
|
149
|
+
"Authorization": "Bearer 2063fef58d79e1b052b62703399fb76d3a27c3c95014f519ddd9a756dfa0d5e7b5aaddbed059ffe269ad6304504763092e6cb8854c6ec56896f9e9d3238abf3a"
|
|
150
|
+
}
|
|
151
|
+
}).then(response => {
|
|
152
|
+
expect(response.status).to.equal(404, "Accepting friend request should have failed with HTTP 404; different code was found instead!");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('Accepting friend request should succeed', () => {
|
|
157
|
+
cy.task('prepPendingFriendRequests');
|
|
158
|
+
|
|
159
|
+
cy.request({
|
|
160
|
+
method: "patch",
|
|
161
|
+
url: "friend-requests/2/accept",
|
|
162
|
+
headers: {
|
|
163
|
+
"Authorization": "Bearer 2063fef58d79e1b052b62703399fb76d3a27c3c95014f519ddd9a756dfa0d5e7b5aaddbed059ffe269ad6304504763092e6cb8854c6ec56896f9e9d3238abf3a"
|
|
164
|
+
}
|
|
165
|
+
}).then(response => {
|
|
166
|
+
expect(response.status).to.equal(200, "Accepting friend request should have succeeded; got non-success code instead!");
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Reject pending friend request
|
|
171
|
+
// in this group; using bearer of second test user because rejecting is from
|
|
172
|
+
// the requested user's perspective
|
|
173
|
+
it('Rejecting friend request should fail due to invalid bearer token', () => {
|
|
174
|
+
cy.task('prepPendingFriendRequests');
|
|
175
|
+
|
|
176
|
+
cy.request({
|
|
177
|
+
failOnStatusCode: false,
|
|
178
|
+
method: "patch",
|
|
179
|
+
url: "friend-requests/2/reject",
|
|
180
|
+
headers: {
|
|
181
|
+
"Authorization": "Bearer invalidBearer"
|
|
182
|
+
}
|
|
183
|
+
}).then(response => {
|
|
184
|
+
expect(response.status).to.equal(401, "Rejecting friend request should have failed with HTTP 401; different code was found instead!");
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('Rejecting friend request should fail due to invalid user ID', () => {
|
|
189
|
+
cy.task('prepPendingFriendRequests');
|
|
190
|
+
|
|
191
|
+
cy.request({
|
|
192
|
+
failOnStatusCode: false,
|
|
193
|
+
method: "patch",
|
|
194
|
+
url: "friend-requests/99/reject",
|
|
195
|
+
headers: {
|
|
196
|
+
"Authorization": "Bearer 2063fef58d79e1b052b62703399fb76d3a27c3c95014f519ddd9a756dfa0d5e7b5aaddbed059ffe269ad6304504763092e6cb8854c6ec56896f9e9d3238abf3a"
|
|
197
|
+
}
|
|
198
|
+
}).then(response => {
|
|
199
|
+
expect(response.status).to.equal(404, "Rejecting friend request should have failed with HTTP 404; different code was found instead!");
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('Rejecting friend request should succeed', () => {
|
|
204
|
+
cy.task('prepPendingFriendRequests');
|
|
205
|
+
|
|
206
|
+
cy.request({
|
|
207
|
+
method: "patch",
|
|
208
|
+
url: "friend-requests/2/reject",
|
|
209
|
+
headers: {
|
|
210
|
+
"Authorization": "Bearer 2063fef58d79e1b052b62703399fb76d3a27c3c95014f519ddd9a756dfa0d5e7b5aaddbed059ffe269ad6304504763092e6cb8854c6ec56896f9e9d3238abf3a"
|
|
211
|
+
}
|
|
212
|
+
}).then(response => {
|
|
213
|
+
expect(response.status).to.equal(200, "Rejecting friend request should have succeeded; got non-success code instead!");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Remove friend
|
|
218
|
+
it('Removing friend should fail due to invalid bearer token', () => {
|
|
219
|
+
cy.task('prepAcceptedFriendRequests');
|
|
220
|
+
|
|
221
|
+
cy.request({
|
|
222
|
+
failOnStatusCode: false,
|
|
223
|
+
method: "delete",
|
|
224
|
+
url: "users/friends/3",
|
|
225
|
+
headers: {
|
|
226
|
+
"Authorization": "Bearer invalidBearer"
|
|
227
|
+
}
|
|
228
|
+
}).then(response => {
|
|
229
|
+
expect(response.status).to.equal(401, "Removing friend should have failed with HTTP 401; different code was found instead!");
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('Removing friend should fail due to invalid friend ID', () => {
|
|
234
|
+
cy.task('prepAcceptedFriendRequests');
|
|
235
|
+
|
|
236
|
+
cy.request({
|
|
237
|
+
failOnStatusCode: false,
|
|
238
|
+
method: "delete",
|
|
239
|
+
url: "users/friends/99",
|
|
240
|
+
headers: {
|
|
241
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
242
|
+
}
|
|
243
|
+
}).then(response => {
|
|
244
|
+
expect(response.status).to.equal(404, "Removing friend should have failed with HTTP 404; different code was found instead!");
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('Removing friend should succeed', () => {
|
|
249
|
+
cy.task('prepAcceptedFriendRequests');
|
|
250
|
+
|
|
251
|
+
cy.request({
|
|
252
|
+
failOnStatusCode: false,
|
|
253
|
+
method: "delete",
|
|
254
|
+
url: "users/friends/3",
|
|
255
|
+
headers: {
|
|
256
|
+
"Authorization": "Bearer 9d2272fd048bfeedda522935244fc4450fb61a9da6f7b7cea529c6c11033e9efee6b140b6e4b372f0c81a07a6e040be5150f506922e8a5c47719f7be2c707252"
|
|
257
|
+
}
|
|
258
|
+
}).then(response => {
|
|
259
|
+
expect(response.status).to.equal(200, "Removing friend should have succeeded; got non-success code instead!");
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
@@ -8,8 +8,15 @@ export default defineConfig({
|
|
|
8
8
|
// drop test artifacts
|
|
9
9
|
async reseedUsersTable() {
|
|
10
10
|
return await prisma.$transaction([
|
|
11
|
-
prisma
|
|
12
|
-
|
|
11
|
+
prisma.users.deleteMany({
|
|
12
|
+
where: {
|
|
13
|
+
user_id: {
|
|
14
|
+
notIn: [2, 3]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
prisma.$executeRaw`UPDATE users SET is_soft_deleted = 0, first_name = 'Unit', last_name = 'Test', username = 'UnitTester' WHERE user_id = 2;`,
|
|
19
|
+
prisma.$executeRaw`UPDATE users SET is_soft_deleted = 0, first_name = 'Unit', last_name = 'Test Jr.', username = 'UnitTester2' WHERE user_id = 3;`,
|
|
13
20
|
]);
|
|
14
21
|
},
|
|
15
22
|
|
|
@@ -45,6 +52,42 @@ export default defineConfig({
|
|
|
45
52
|
return await prisma.$transaction([
|
|
46
53
|
prisma.$executeRaw`REPLACE INTO User_Activity_Posts (post_id, user_id, category_name, activity_id, post_date, post_status, caption) VALUES (1, 2, 'Professional', 1, '2026-02-28 22:15:02', 'public', 'This is a test post! Nothing much going on here...');`
|
|
47
54
|
])
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
// tasks used for friend request unit tests to work correctly
|
|
58
|
+
async clearFriendRequestsTable() {
|
|
59
|
+
return await prisma.$transaction([
|
|
60
|
+
prisma.friend_Requests.deleteMany({})
|
|
61
|
+
])
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
async prepAcceptedFriendRequests() {
|
|
65
|
+
const [res] = await prisma.$transaction([
|
|
66
|
+
prisma.friend_Requests.create({
|
|
67
|
+
data: {
|
|
68
|
+
friend_request_id: 1,
|
|
69
|
+
initiator_user_id: 2,
|
|
70
|
+
target_user_id: 3,
|
|
71
|
+
status: "accepted"
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
]);
|
|
75
|
+
return !!res;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
async prepPendingFriendRequests() {
|
|
79
|
+
const [res] = await prisma.$transaction([
|
|
80
|
+
prisma.friend_Requests.create({
|
|
81
|
+
data: {
|
|
82
|
+
friend_request_id: 1,
|
|
83
|
+
initiator_user_id: 2,
|
|
84
|
+
target_user_id: 3,
|
|
85
|
+
status: "pending"
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
return !!res;
|
|
48
91
|
}
|
|
49
92
|
})
|
|
50
93
|
},
|
package/rest-api/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import * as SchoolFunctions from "./routes/SchoolFunctions.js";
|
|
|
9
9
|
import * as CategoryFunctions from "./routes/CategoryFunctions.js";
|
|
10
10
|
import * as UserActivityFunctions from "./routes/UserActivityFunctions.js";
|
|
11
11
|
import * as ActivityPostFunctions from "./routes/ActivityPostFunctions.js";
|
|
12
|
+
import * as FriendFunctions from "./routes/FriendFunctions.js";
|
|
12
13
|
|
|
13
14
|
const spec = yamlLoad(readFileSync("./api-spec.yaml"));
|
|
14
15
|
|
|
@@ -42,7 +43,13 @@ const handler = {
|
|
|
42
43
|
getFeed: ActivityPostFunctions.getFeedHandler,
|
|
43
44
|
getPostById: ActivityPostFunctions.getPostByIdHandler,
|
|
44
45
|
updatePost: ActivityPostFunctions.updatePostHandler,
|
|
45
|
-
deletePost: ActivityPostFunctions.deletePostHandler
|
|
46
|
+
deletePost: ActivityPostFunctions.deletePostHandler,
|
|
47
|
+
listFriends: FriendFunctions.listFriendsHandler,
|
|
48
|
+
sendFriendRequest: FriendFunctions.sendFriendRequestHandler,
|
|
49
|
+
acceptFriendRequest: FriendFunctions.acceptFriendRequestHandler,
|
|
50
|
+
rejectFriendRequest: FriendFunctions.rejectFriendRequestHandler,
|
|
51
|
+
pendingFriendRequests: FriendFunctions.pendingFriendRequestsHandler,
|
|
52
|
+
removeFriend: FriendFunctions.removeFriendHandler
|
|
46
53
|
};
|
|
47
54
|
|
|
48
55
|
fastify.register(oasFastify, { spec, handler });
|
package/rest-api/lib/users.js
CHANGED
|
@@ -10,16 +10,18 @@ export async function getUserAuthInfo(prisma, accessToken) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export async function areUsersFriends(prisma, userId, targetPotentialFriendId) {
|
|
13
|
-
const friendInfo = await prisma.
|
|
13
|
+
const friendInfo = await prisma.Friend_Requests.findFirst({
|
|
14
14
|
where: {
|
|
15
15
|
OR: [
|
|
16
16
|
{
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
initiator_user_id: userId,
|
|
18
|
+
target_user_id: targetPotentialFriendId,
|
|
19
|
+
status: "accepted"
|
|
19
20
|
},
|
|
20
21
|
{
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
initiator_user_id: targetPotentialFriendId,
|
|
23
|
+
target_user_id: userId,
|
|
24
|
+
status: "accepted"
|
|
23
25
|
},
|
|
24
26
|
],
|
|
25
27
|
},
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { getUserAuthInfo, areUsersFriends } from "../lib/users.js";
|
|
2
|
+
|
|
3
|
+
export async function listFriendsHandler(request, reply, fastify) {
|
|
4
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
5
|
+
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
6
|
+
|
|
7
|
+
if (userInfo === null) {
|
|
8
|
+
reply.status(401);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const targetUserCheck = await fastify.prisma.users.findFirst({
|
|
13
|
+
where: {
|
|
14
|
+
user_id: request.params.id
|
|
15
|
+
},
|
|
16
|
+
select: {
|
|
17
|
+
user_id: true
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (targetUserCheck === null) {
|
|
21
|
+
reply.status(404);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const friendsList = await fastify.prisma.Friend_Requests.findMany({
|
|
26
|
+
where: {
|
|
27
|
+
OR: [
|
|
28
|
+
{ initiator_user_id: request.params.id, status: "accepted" },
|
|
29
|
+
{ target_user_id: request.params.id, status: "accepted" }
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
select: {
|
|
33
|
+
users_Friend_Requests_initiator_user_idTousers: {
|
|
34
|
+
select: {
|
|
35
|
+
user_id: true,
|
|
36
|
+
first_name: true,
|
|
37
|
+
last_name: true,
|
|
38
|
+
username: true,
|
|
39
|
+
email: true,
|
|
40
|
+
school: {
|
|
41
|
+
select: { school_id: true, school_name: true }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
users_Friend_Requests_target_user_idTousers: {
|
|
46
|
+
select: {
|
|
47
|
+
user_id: true,
|
|
48
|
+
first_name: true,
|
|
49
|
+
last_name: true,
|
|
50
|
+
username: true,
|
|
51
|
+
email: true,
|
|
52
|
+
school: {
|
|
53
|
+
select: { school_id: true, school_name: true }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return friendsList.map(friendEntry => {
|
|
61
|
+
// determine which side of the relationship is the friend (not the current user)
|
|
62
|
+
const friend = Number(friendEntry.users_Friend_Requests_initiator_user_idTousers.user_id) === request.params.id
|
|
63
|
+
? friendEntry.users_Friend_Requests_target_user_idTousers
|
|
64
|
+
: friendEntry.users_Friend_Requests_initiator_user_idTousers;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
userId: Number(friend.user_id),
|
|
68
|
+
firstName: friend.first_name,
|
|
69
|
+
lastName: friend.last_name,
|
|
70
|
+
username: friend.username,
|
|
71
|
+
email: friend.email,
|
|
72
|
+
schoolId: Number(friend.school.school_id),
|
|
73
|
+
schoolName: friend.school.school_name,
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function pendingFriendRequestsHandler(request, reply, fastify) {
|
|
79
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
80
|
+
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
81
|
+
|
|
82
|
+
if (userInfo === null) {
|
|
83
|
+
reply.status(401);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const pendingFriendRequests = await fastify.prisma.Friend_Requests.findMany({
|
|
88
|
+
where: {
|
|
89
|
+
target_user_id: userInfo.user_id,
|
|
90
|
+
status: "pending"
|
|
91
|
+
},
|
|
92
|
+
select: {
|
|
93
|
+
users_Friend_Requests_initiator_user_idTousers: {
|
|
94
|
+
select: {
|
|
95
|
+
user_id: true,
|
|
96
|
+
first_name: true,
|
|
97
|
+
last_name: true,
|
|
98
|
+
username: true,
|
|
99
|
+
email: true,
|
|
100
|
+
school: {
|
|
101
|
+
select: { school_id: true, school_name: true }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return pendingFriendRequests.map(friendRequest => ({
|
|
109
|
+
userId: Number(friendRequest.users_Friend_Requests_initiator_user_idTousers.user_id),
|
|
110
|
+
firstName: friendRequest.users_Friend_Requests_initiator_user_idTousers.first_name,
|
|
111
|
+
lastName: friendRequest.users_Friend_Requests_initiator_user_idTousers.last_name,
|
|
112
|
+
username: friendRequest.users_Friend_Requests_initiator_user_idTousers.username,
|
|
113
|
+
email: friendRequest.users_Friend_Requests_initiator_user_idTousers.email,
|
|
114
|
+
schoolId: Number(friendRequest.users_Friend_Requests_initiator_user_idTousers.school.school_id),
|
|
115
|
+
schoolName: friendRequest.users_Friend_Requests_initiator_user_idTousers.school.school_name,
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function sendFriendRequestHandler(request, reply, fastify) {
|
|
120
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
121
|
+
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
122
|
+
|
|
123
|
+
if (userInfo === null) {
|
|
124
|
+
reply.status(401);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const targetUserInfo = await fastify.prisma.users.findFirst({
|
|
129
|
+
where: {
|
|
130
|
+
user_id: request.params.id
|
|
131
|
+
},
|
|
132
|
+
select: {
|
|
133
|
+
user_id: true
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (targetUserInfo === null) {
|
|
137
|
+
reply.status(404);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const areFriends = await areUsersFriends(fastify.prisma, userInfo.user_id, request.params.id);
|
|
142
|
+
if (areFriends) {
|
|
143
|
+
reply.status(400);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await fastify.prisma.Friend_Requests.create({
|
|
148
|
+
data: {
|
|
149
|
+
initiator_user_id: userInfo.user_id,
|
|
150
|
+
target_user_id: request.params.id
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
reply.status(201);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// TODO move the core functionality code to a separate
|
|
158
|
+
// library function since accept and reject friend request
|
|
159
|
+
// are both very similar
|
|
160
|
+
export async function acceptFriendRequestHandler(request, reply, fastify) {
|
|
161
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
162
|
+
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
163
|
+
|
|
164
|
+
if (userInfo === null) {
|
|
165
|
+
reply.status(401);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const friendRequest = await fastify.prisma.Friend_Requests.findFirst({
|
|
170
|
+
where: {
|
|
171
|
+
target_user_id: userInfo.user_id,
|
|
172
|
+
initiator_user_id: request.params.id,
|
|
173
|
+
status: "pending"
|
|
174
|
+
},
|
|
175
|
+
select: {
|
|
176
|
+
friend_request_id: true
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (friendRequest === null) {
|
|
181
|
+
reply.status(404);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
await fastify.prisma.Friend_Requests.update({
|
|
186
|
+
where: {
|
|
187
|
+
friend_request_id: friendRequest.friend_request_id
|
|
188
|
+
},
|
|
189
|
+
data: {
|
|
190
|
+
status: "accepted"
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function rejectFriendRequestHandler(request, reply, fastify) {
|
|
196
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
197
|
+
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
198
|
+
|
|
199
|
+
if (userInfo === null) {
|
|
200
|
+
reply.status(401);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const friendRequest = await fastify.prisma.Friend_Requests.findFirst({
|
|
205
|
+
where: {
|
|
206
|
+
target_user_id: userInfo.user_id,
|
|
207
|
+
initiator_user_id: request.params.id,
|
|
208
|
+
status: "pending"
|
|
209
|
+
},
|
|
210
|
+
select: {
|
|
211
|
+
friend_request_id: true
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (friendRequest === null) {
|
|
216
|
+
reply.status(404);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
await fastify.prisma.Friend_Requests.delete({
|
|
221
|
+
where: {
|
|
222
|
+
friend_request_id: friendRequest.friend_request_id
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function removeFriendHandler(request, reply, fastify) {
|
|
228
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
229
|
+
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
230
|
+
|
|
231
|
+
if (userInfo === null) {
|
|
232
|
+
reply.status(401);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const friendship = await fastify.prisma.Friend_Requests.findFirst({
|
|
237
|
+
where: {
|
|
238
|
+
OR: [
|
|
239
|
+
{
|
|
240
|
+
initiator_user_id: userInfo.user_id,
|
|
241
|
+
target_user_id: request.params.friendId,
|
|
242
|
+
status: "accepted"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
initiator_user_id: request.params.friendId,
|
|
246
|
+
target_user_id: userInfo.user_id,
|
|
247
|
+
status: "accepted"
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
select: {
|
|
252
|
+
friend_request_id: true
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
if (friendship === null) {
|
|
257
|
+
reply.status(404);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
await fastify.prisma.Friend_Requests.delete({
|
|
262
|
+
where: {
|
|
263
|
+
friend_request_id: friendship.friend_request_id
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getUserAuthInfo, areUsersFriends } from "../lib/users.js";
|
|
2
2
|
|
|
3
3
|
export async function getUserActivitiesHandler(request, reply, fastify) {
|
|
4
|
-
const accessToken = (request.headers.authorization ?? "").substring(7)
|
|
4
|
+
const accessToken = (request.headers.authorization ?? "").substring(7);
|
|
5
5
|
const targetUserId = request.params.id;
|
|
6
6
|
const userInfo = await getUserAuthInfo(fastify.prisma, accessToken);
|
|
7
7
|
|