@@ -15,12 +15,18 @@ import {
15
15
INVALID_REQUEST_TYPE ,
16
16
} from "../constants/requests" ;
17
17
import { getRequests , updateRequest } from "../models/requests" ;
18
- import { AcknowledgeOOORequestBody } from "../types/oooRequest" ;
19
- import { statusState } from "../constants/userStatus" ;
20
- import { createUserFutureStatus } from "../models/userFutureStatus" ;
18
+ import { AcknowledgeOOORequestBody , OooStatusRequest } from "../types/oooRequest" ;
21
19
import { addFutureStatus } from "../models/userStatus" ;
22
20
const requestModel = firestore . collection ( "requests" ) ;
23
21
22
+ /**
23
+ * Validates an Out-Of-Office (OOO) acknowledge request
24
+ *
25
+ * @param {string } requestId - The unique identifier of the request.
26
+ * @param {string } requestType - The type of the request (expected to be 'OOO').
27
+ * @param {string } requestStatus - The current status of the request.
28
+ * @throws {Error } Throws an error if an issue occurs during validation.
29
+ */
24
30
export const validateOOOAcknowledgeRequest = async (
25
31
requestId : string ,
26
32
requestType : string ,
@@ -58,10 +64,19 @@ export const validateOOOAcknowledgeRequest = async (
58
64
}
59
65
}
60
66
67
+ /**
68
+ * Acknowledges an Out-of-Office (OOO) request
69
+ *
70
+ * @param {string } requestId - The ID of the OOO request to acknowledge.
71
+ * @param {AcknowledgeOOORequestBody } body - The acknowledgement body containing acknowledging details.
72
+ * @param {string } userId - The unique identifier of the superuser user.
73
+ * @returns {Promise<object> } The acknowledged OOO request.
74
+ * @throws {Error } Throws an error if an issue occurs during acknowledgment process.
75
+ */
61
76
export const acknowledgeOOORequest = async (
62
77
requestId : string ,
63
78
body : AcknowledgeOOORequestBody ,
64
- userId : string ,
79
+ superUserId : string ,
65
80
) => {
66
81
try {
67
82
const request = await requestModel . doc ( requestId ) . get ( ) ;
@@ -78,7 +93,7 @@ export const acknowledgeOOORequest = async (
78
93
79
94
await validateOOOAcknowledgeRequest ( requestId , requestData . type , requestData . status ) ;
80
95
81
- const requestResult = await updateRequest ( requestId , body , userId , REQUEST_TYPE . OOO ) ;
96
+ const requestResult = await updateRequest ( requestId , body , superUserId , REQUEST_TYPE . OOO ) ;
82
97
83
98
if ( "error" in requestResult ) {
84
99
throw BadRequest ( requestResult . error ) ;
@@ -94,7 +109,7 @@ export const acknowledgeOOORequest = async (
94
109
meta : {
95
110
requestId : requestId ,
96
111
action : LOG_ACTION . UPDATE ,
97
- userId : userId ,
112
+ userId : superUserId ,
98
113
createdAt : Date . now ( ) ,
99
114
} ,
100
115
body : requestResult ,
@@ -103,20 +118,16 @@ export const acknowledgeOOORequest = async (
103
118
await addLog ( requestLog . type , requestLog . meta , requestLog . body ) ;
104
119
105
120
if ( requestResult . status === REQUEST_STATE . APPROVED ) {
106
- const requestData = await getRequests ( { id : requestId } ) ;
107
-
108
121
if ( requestData ) {
109
- const { from, until, requestedBy , comment } = requestData as any ;
122
+ const { from, until, userId } = requestData ;
110
123
const userFutureStatusData = {
111
124
requestId,
112
- status : REQUEST_TYPE . OOO ,
113
- state : statusState . UPCOMING ,
125
+ state : REQUEST_TYPE . OOO ,
114
126
from,
115
127
endsOn : until ,
116
- userId : requestedBy ,
117
- message : comment ,
128
+ userId,
129
+ message : body . comment ,
118
130
} ;
119
- await createUserFutureStatus ( userFutureStatusData ) ;
120
131
await addFutureStatus ( userFutureStatusData ) ;
121
132
}
122
133
}
0 commit comments