Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated user_search query param, changed status for unauthorized error #146

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -70,7 +70,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 @@ -135,7 +135,7 @@ Later, the subsequent logins can be done via `token`:
{
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