Seeking guidance on how to set a boolean value inside an action in NGXS, as I am new to it.
Below is the interface I am working with:
export interface CertificateObject {
certificateName: string;
issueDate: Date;
expiryDate: Date;
thumbPrint: string;
serialNumber: string;
daysToExpire: number;
aboutToExpire: boolean;
}
Here is my state model configuration:
export interface CertificateStateModel {
certificates: CertificateObject[];
filteredCertificates: CertificateObject[];
searchLimitedStateMessage: string;
emptyCertificateMessage: string;
searchTerm: string;
}
And this is the action implementation:
@Action(CertificateAction.GetAllCertificates)
getAllCertificates(
ctx: StateContext<CertificateStateModel>,
action: CertificateAction.GetAllCertificates
) {
ctx.dispatch(new Busy(true));
return this.svc.getIACertificates().pipe(
tap((certsResponse) => {
ctx.patchState({
certificates: certsResponse.certificates.map(cert => ({
...cert,
})),
filteredCertificates: certsResponse.certificates.map(cert => ({
...cert,
})),
});
ctx.dispatch(new Busy(false));
},
(error: any) => {
ctx.dispatch([
new DisplayMessage({type: "error", list: [ "Get All Certificates Error", error.error ]}),
new Busy(false)
]);
})
);
}
I am looking for a way to evaluate the daysToExpire property and set aboutToExpire to True if less than 61. Currently handling this logic in the template but aiming to move it to the action itself. Any suggestions would be greatly appreciated. Thank you!