generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OOO request approved data to user future status (#2001)
* added all changes * create new status if user not have any status * refactor: result schema * test: add test for user future status model functions * test: add test for add futire staus to user status model. * refactor addFutureStatus user status model function --------- Co-authored-by: Amit Prakash <34869115+iamitprakash@users.noreply.github.com>
- Loading branch information
1 parent
1969a37
commit 7fb0e0e
Showing
11 changed files
with
191 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
const userState = { | ||
export const userState = { | ||
ACTIVE: "ACTIVE", | ||
IDLE: "IDLE", | ||
OOO: "OOO", | ||
ONBOARDING: "ONBOARDING", | ||
}; | ||
|
||
const CANCEL_OOO = "cancelOoo"; | ||
export const statusState = { | ||
UPCOMING: "UPCOMING", | ||
APPLIED: "APPLIED", | ||
NOT_APPLIED: "NOT_APPLIED", | ||
}; | ||
|
||
module.exports = { userState, CANCEL_OOO }; | ||
export const CANCEL_OOO = "cancelOoo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import firestore from "../utils/firestore"; | ||
const userFutureStatusModel = firestore.collection("userFutureStatus"); | ||
import { UserFutureStatusType } from "../types/userFutureStatus"; | ||
import * as admin from "firebase-admin"; | ||
|
||
/** | ||
* Function to create user future status | ||
* @param body: UserFutureStatusType | ||
* @returns UserFutureStatusType | ||
*/ | ||
export const createUserFutureStatus = async (body: UserFutureStatusType) => { | ||
try { | ||
const statusBody: UserFutureStatusType = { | ||
createdAt: Date.now(), | ||
...body, | ||
}; | ||
const resultDoc = await userFutureStatusModel.add(statusBody); | ||
return { | ||
id: resultDoc.id, | ||
...body, | ||
}; | ||
} catch (error) { | ||
logger.error("Error while creating user future status", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
/** | ||
* Function to get user future status | ||
* @param: id: string, status: string, state: string | ||
* @returns Array of user future status | ||
**/ | ||
export const getUserFutureStatus = async (userId: string, status: string, state: string) => { | ||
try { | ||
let resultArray = []; | ||
let query: admin.firestore.Query = userFutureStatusModel; | ||
|
||
if (userId) { | ||
query = query.where("userId", "==", userId); | ||
} | ||
if (status) { | ||
query = query.where("status", "==", status); | ||
} | ||
if (state) { | ||
query = query.where("state", "==", state); | ||
} | ||
const resultDoc = await query.get(); | ||
resultDoc.forEach((doc) => { | ||
resultArray.push({ id: doc.id, ...doc.data() }); | ||
}); | ||
return resultArray; | ||
} catch (error) { | ||
logger.error("Error while fetching user future status", error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { REQUEST_TYPE } from "../../../constants/requests"; | ||
import { statusState } from "../../../constants/userStatus"; | ||
|
||
export const userFutureStatusData = { | ||
requestId: "randomId", | ||
status: REQUEST_TYPE.OOO, | ||
state: statusState.UPCOMING, | ||
from: 1712277700000, | ||
endsOn: 1712277700000, | ||
userId: "randomUserId", | ||
message: "I am out of office", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createUserFutureStatus, getUserFutureStatus } from "../../../models/userFutureStatus"; | ||
import { expect } from "chai"; | ||
import cleanDb from "../../utils/cleanDb"; | ||
import { UserFutureStatusType } from "../../../types/userFutureStatus"; | ||
import { userFutureStatusData } from "../../fixtures/userFutureStatus/userFutureStatusData"; | ||
|
||
describe("models/userFutureStatus", () => { | ||
afterEach(async () => { | ||
await cleanDb(); | ||
}); | ||
|
||
describe("createUserFutureStatus ", () => { | ||
it("should successfully create a new user future status", async () => { | ||
const userFutureStatus = await createUserFutureStatus(userFutureStatusData as UserFutureStatusType); | ||
expect(userFutureStatus).to.not.be.null; | ||
expect(userFutureStatus).to.have.property("id"); | ||
expect(userFutureStatus).to.have.property("userId"); | ||
}); | ||
}); | ||
|
||
describe("getUserFutureStatus", () => { | ||
it("should successfully get user future status", async () => { | ||
await createUserFutureStatus(userFutureStatusData as UserFutureStatusType); | ||
const userFutureStatus = await getUserFutureStatus( | ||
userFutureStatusData.userId, | ||
userFutureStatusData.status, | ||
userFutureStatusData.state | ||
); | ||
expect(userFutureStatus).to.not.be.null; | ||
expect(userFutureStatus).to.be.an("array"); | ||
expect(userFutureStatus).to.have.length(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { userState, statusState } from "../constants/userStatus"; | ||
|
||
export type UserFutureStatusType = { | ||
id?: string; | ||
requestId?: string; | ||
status: userState.OOO | userState.IDLE | userState.ACTIVE; | ||
state: statusState.UPCOMING | statusState.APPLIED | statusState.NOT_APPLIED; | ||
from: number; | ||
endsOn?: number; | ||
userId: string; | ||
message?: string; | ||
createdAt?: number; | ||
}; |