Skip to content

Commit

Permalink
Updated user_search query param, changed status for unauthorized
Browse files Browse the repository at this point in the history
…error (#146)

* Updated user_search param name & updated error status for `Unauthorized`

* added logs

* removed logs
  • Loading branch information
Oleksandr1414 authored Jan 22, 2025
1 parent 302cbba commit 236088e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion APIs/JSON/validations/users_schema_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const usersSchemaValidation = {
logout: Joi.object({}).required(),
delete: Joi.object({}).required(),
search: Joi.object({
login: Joi.string().required(),
keyword: Joi.string().required(),
limit: Joi.number().min(1).max(100),
updated_at: Joi.object({
gt: Joi.date(),
Expand Down
2 changes: 1 addition & 1 deletion app/constants/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const ERROR_STATUES = {
// Default -->
UNAUTHORIZED: { status: 404, message: "Unauthorized." },
UNAUTHORIZED: { status: 401, message: "Unauthorized." },
FORBIDDEN: { status: 403, message: "Forbidden." },
BAD_REQUEST: { status: 400, message: "Bad Request." },
INVALID_DATA_FORMAT: {
Expand Down
3 changes: 1 addition & 2 deletions app/providers/operations/user/search/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CONSTANTS as MAIN_CONSTANTS } from "../../../../constants/constants.js"
import { slice } from "@sama/utils/req_res_utils.js"

class UserSearchOperation {
constructor(sessionService, userService) {
Expand All @@ -17,7 +16,7 @@ class UserSearchOperation {
: searchParams.limit || MAIN_CONSTANTS.LIMIT_MAX

const users = await this.userService.userRepo.search(
{ match: searchParams.login, ignoreIds, timeFromUpdate: searchParams.updated_at?.gt },
{ match: searchParams.keyword, ignoreIds, timeFromUpdate: searchParams.updated_at?.gt },
limit
)

Expand Down
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Old websocket requests examples:
{
request: {
user_search: {
login: "sam",
keyword: "sam",
limit: 100,
updated_at: {
gt: timestamp_in_ms,
Expand Down
6 changes: 3 additions & 3 deletions test/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("Conversation functions", async () => {

assert.strictEqual(responseData.response.conversation, undefined)
assert.deepEqual(responseData.response.error, {
status: 404,
status: 401,
message: "Unauthorized.",
})
})
Expand All @@ -91,7 +91,7 @@ describe("Conversation functions", async () => {

assert.strictEqual(responseData.response.success, undefined)
assert.deepEqual(responseData.response.error, {
status: 404,
status: 401,
message: "Unauthorized.",
})
})
Expand All @@ -112,7 +112,7 @@ describe("Conversation functions", async () => {

assert.strictEqual(responseData.response.success, undefined)
assert.deepEqual(responseData.response.error, {
status: 404,
status: 401,
message: "Unauthorized.",
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/status_typing.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe(`Sending 'typing' status`, async () => {

assert.strictEqual(responseData.typing.user, undefined)
assert.deepEqual(responseData.typing.error, {
status: 404,
status: 401,
message: "Unauthorized.",
})

Expand Down
4 changes: 2 additions & 2 deletions test/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ describe("User cycle", async () => {
assert.strictEqual(requestData.request.id, responseData.response.id)
assert.strictEqual(responseData.response.success, undefined)
assert.deepEqual(responseData.response.error, {
status: 404,
status: 401,
message: "Unauthorized.",
})
})
Expand All @@ -626,7 +626,7 @@ describe("User cycle", async () => {
assert.strictEqual(requestData.request.id, responseData.response.id)
assert.strictEqual(responseData.response.success, undefined)
assert.deepEqual(responseData.response.error, {
status: 404,
status: 401,
message: "Unauthorized.",
})

Expand Down

0 comments on commit 236088e

Please sign in to comment.