Add validation for contract dates
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -151,6 +151,23 @@ function NewPeopleViewContent() {
|
|||||||
description: error.message || "Failed to create person",
|
description: error.message || "Failed to create person",
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultErrorValues = {
|
||||||
|
title: "Error",
|
||||||
|
description: error.message || "Failed to save changes",
|
||||||
|
variant: "destructive" as const
|
||||||
|
};
|
||||||
|
|
||||||
|
if (error.message?.includes("contract end date must be after or equal to start date")) {
|
||||||
|
toast({
|
||||||
|
...defaultErrorValues,
|
||||||
|
description:
|
||||||
|
"Contract end date must be after or equal to start date.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toast(defaultErrorValues);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -143,21 +143,29 @@ function PeopleViewContent({
|
|||||||
setEditedFields(new Set());
|
setEditedFields(new Set());
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
const defaultErrorValues = {
|
||||||
|
title: "Error",
|
||||||
|
description: error.message || "Failed to save changes",
|
||||||
|
variant: "destructive" as const
|
||||||
|
};
|
||||||
|
|
||||||
if (error.message?.includes("concurrent modification")) {
|
if (error.message?.includes("concurrent modification")) {
|
||||||
toast({
|
toast({
|
||||||
title: "Error",
|
...defaultErrorValues,
|
||||||
description:
|
description: "Someone else modified this person. Reloading latest data.",
|
||||||
"Someone else modified this person. Reloading latest data.",
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
});
|
||||||
loadQuery({ peopleId: data.node.id! });
|
loadQuery({ peopleId: data.node.id! });
|
||||||
} else {
|
}
|
||||||
|
else if (error.message?.includes("contract end date must be after or equal to start date")) {
|
||||||
toast({
|
toast({
|
||||||
title: "Error",
|
...defaultErrorValues,
|
||||||
description: error.message || "Failed to save changes",
|
description:
|
||||||
variant: "destructive",
|
"Contract end date must be after or equal to start date.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
toast(defaultErrorValues);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, [commit, data.node.id, formData, loadQuery, toast]);
|
}, [commit, data.node.id, formData, loadQuery, toast]);
|
||||||
|
|||||||
@@ -161,6 +161,12 @@ func (s PeopleService) Update(
|
|||||||
people.ContractEndDate = *req.ContractEndDate
|
people.ContractEndDate = *req.ContractEndDate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if people.ContractStartDate != nil && people.ContractEndDate != nil {
|
||||||
|
if people.ContractEndDate.Before(*people.ContractStartDate) {
|
||||||
|
return fmt.Errorf("contract end date must be after or equal to start date")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
people.UpdatedAt = time.Now()
|
people.UpdatedAt = time.Now()
|
||||||
|
|
||||||
return people.Update(ctx, conn, s.svc.scope)
|
return people.Update(ctx, conn, s.svc.scope)
|
||||||
@@ -176,6 +182,12 @@ func (s PeopleService) Create(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req CreatePeopleRequest,
|
req CreatePeopleRequest,
|
||||||
) (*coredata.People, error) {
|
) (*coredata.People, error) {
|
||||||
|
if req.ContractStartDate != nil && req.ContractEndDate != nil {
|
||||||
|
if req.ContractEndDate.Before(*req.ContractStartDate) {
|
||||||
|
return nil, fmt.Errorf("contract end date must be after or equal to start date")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
peopleID := gid.New(s.svc.scope.GetTenantID(), coredata.PeopleEntityType)
|
peopleID := gid.New(s.svc.scope.GetTenantID(), coredata.PeopleEntityType)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user