Approve a leave request when the employee has enough balance and gives sufficient notice.
A **leave_request** is approved
if the __remaining_days__ of the **employee** is greater than or equal to the __days_requested__ of the **leave_request**
and the __notice_days__ of the **leave_request** is greater than or equal to 5
and the __is_blackout_period__ of the **leave_request** is equal to false.
{
"properties": {
"employee": {
"properties": {
"remaining_days": {
"type": "number"
}
},
"required": [
"remaining_days"
],
"type": "object"
},
"leave_request": {
"properties": {
"days_requested": {
"type": "number"
},
"notice_days": {
"type": "number"
},
"is_blackout_period": {
"type": "boolean"
}
},
"required": [
"days_requested",
"notice_days",
"is_blackout_period"
],
"type": "object"
}
},
"required": [
"employee",
"leave_request"
],
"title": "Leave Request Model",
"type": "object"
}Valid leave request
Expect pass{
"employee": {
"remaining_days": 15
},
"leave_request": {
"days_requested": 5,
"notice_days": 14,
"is_blackout_period": false
}
}Insufficient balance
Expect fail{
"employee": {
"remaining_days": 2
},
"leave_request": {
"days_requested": 5,
"notice_days": 14,
"is_blackout_period": false
}
}Execute this policy from your app using one of the official SDKs.
import { ExecutionClient } from "@policies2/sdk";
const client = new ExecutionClient({
apiKey: process.env.POLICY_API_KEY!,
transport: { kind: "rest", baseUrl: "https://api.policy2.net" },
});
const result = await client.executePolicy({
id: "your-policy-id", // replace with your published policy ID
reference: "base",
data: {
"employee": {
"remaining_days": 15
},
"leave_request": {
"days_requested": 5,
"notice_days": 14,
"is_blackout_period": false
}
},
});
if (result.result) {
console.log("policy matched");
} else {
console.log("policy did not match");
}Ready to try this policy?
Open in editor