@causalfoundry/js-sdk
Version:
Causal Foundry WEB SDK (JS/TS)
70 lines (67 loc) • 2.33 kB
text/typescript
import CfExceptionHandler from "../../../core/CfExceptionHandler";
import {injectCatalog} from "../../../core/injector";
import {LoyaltyTypes, RewardCatalog, SurveyCatalog} from "../typings";
export async function validateAndSaveSurveyCatalog(surveyId: string, properties: SurveyCatalog) {
const surveyCatalog = "survey catalog";
if (surveyId == "") {
new CfExceptionHandler().throwAndLogError(
surveyCatalog,
"empty survey catalog id"
);
return;
} else if (properties.name == "") {
new CfExceptionHandler().throwAndLogError(
surveyCatalog,
"empty survey catalog name"
);
return;
} else if (properties.type == undefined) {
new CfExceptionHandler().throwAndLogError(
surveyCatalog,
"invalid survey catalog type"
);
return;
} else if (properties.reward_id == "") {
new CfExceptionHandler().throwAndLogError(
surveyCatalog,
"empty survey catalog reward id"
);
return;
} else if (properties.questions_list.length == 0) {
new CfExceptionHandler().throwAndLogError(
surveyCatalog,
"empty survey catalog questions list"
);
return;
}
injectCatalog(surveyId, LoyaltyTypes.Survey, properties);
}
export async function validateAndSaveRewardCatalog(rewardId: string, properties: RewardCatalog) {
const rewardCatalog = "reward catalog";
if (rewardId == "") {
new CfExceptionHandler().throwAndLogError(
rewardCatalog,
"empty reward catalog id"
);
return;
} else if (properties.name == "") {
new CfExceptionHandler().throwAndLogError(
rewardCatalog,
"empty reward catalog name"
);
return;
} else if (properties.type == undefined) {
new CfExceptionHandler().throwAndLogError(
rewardCatalog,
"invalid reward catalog type"
);
return;
} else if (properties.required_points < 0) {
new CfExceptionHandler().throwAndLogError(
rewardCatalog,
"negative reward catalog reward points"
);
return;
}
injectCatalog(rewardId, LoyaltyTypes.Reward, properties);
}