How to match the enums from the backend with enums in workshop

Hi team,

We are building our backend in TS functions and we are defining enums for several fields on our objects (e.g. patient status).
Unfortunately, we are running into issues when there is a change on the enums in the backend, in the TS repo, which is not replicated on the front end.
To replicate the change, we need to identify all the places where we hardcoded this enum and then manually change every instance of it.
Of course, we are missing some fromt ime to time which is leading to errors.

Is there a way to share enums across the BE and FE ?
Do you have any recommendation or best practice to make this work?

Thanks

hi, could you describe how you are using the enums in Workshop?

Hey Michael - In workshop I use the enums as part of filters on objects

This might not be the best way to solve your issue, but you could write a new TS function that returns the list of enums (keys and values) in a JSON struct. You could then define a new function-backed variable in Workshop that calls this function and stores the returned struct. Then, rather than hard-coding the enum, you can extract the desired enum key from the struct in order to get its enum value.

That’s a great idea.

I created a variable that would only calculate on the module load to avoid increased cost of computation.

Here is how I did it:

In mt TS repo:
export enum PatientStatus {
NewPatient = ‘Nouveau’,
NewTreatmentSent = ‘Nouveau traitement envoyé’,
}

interface PatientStatusFE {
NewPatient: string;
NewTreatmentSent: string;
}

@Function()
public getPatientStatusFE(): PatientStatusFE {
return {
NewPatient: PatientStatus.NewPatient,
NewTreatmentSent: PatientStatus.NewTreatmentSent,
};
}

In workshop:
function backed variable that calls the getPatientStatusFE function + a variable for each enum key from the struct.

Thanks for the help