Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion server/controllers/handleCheckIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export const handleCheckIn = async (req: Request, res: Response) => {
let newOverallTally = overallTally,
newImageSrc = imageSrc;

const analytics: { analyticName: string; uniqueKey?: string }[] = [
{
analyticName: "completions",
uniqueKey: profileId,
},
];

if (todayEntry.users[profileId]) {
//if users is in date mapping (already checked in), return already checked in json message
await visitor
Expand Down Expand Up @@ -66,6 +73,12 @@ export const handleCheckIn = async (req: Request, res: Response) => {
//adding 1 to overall tally
newOverallTally = overallTally + 1;

if (newOverallTally === goal) {
analytics.push({
analyticName: "goal_reached",
});
}

//using updateWebImageLayers to update the image layer
const stage = getStage(newOverallTally, goal);
newImageSrc = getImageSrc(stage);
Expand All @@ -79,7 +92,7 @@ export const handleCheckIn = async (req: Request, res: Response) => {
imageSrc: newImageSrc,
};

await droppedAsset.updateDataObject(updates);
await droppedAsset.updateDataObject(updates, { analytics });

//firing toast for successful check in
visitor
Expand Down
9 changes: 8 additions & 1 deletion server/controllers/handleGetGameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import { VisitorInterface } from "@rtsdk/topia";
export const handleGetGameState = async (req: Request, res: Response) => {
try {
const credentials = getCredentials(req.query);
const { visitorId, urlSlug } = credentials;
const { profileId, visitorId, urlSlug } = credentials;

const droppedAsset: IDroppedAsset = await getDroppedAsset(credentials);

const { dailyCheckIns, goal, overallTally, imageSrc = getImageSrc() } = droppedAsset.dataObject;

const visitor: VisitorInterface = await Visitor.get(visitorId, urlSlug, { credentials });

visitor.updateDataObject(
{},
{
analytics: [{ analyticName: "starts", uniqueKey: profileId }],
},
);

return res.json({
success: true,
message: "Received check in info successfully!",
Expand Down
13 changes: 12 additions & 1 deletion server/controllers/handleUpdateGoal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ import { IDroppedAsset } from "../types/DroppedAssetInterface.js";
export const handleUpdateGoal = async (req: Request, res: Response) => {
try {
const credentials = getCredentials(req.query);
const { profileId } = credentials;

const droppedAsset: IDroppedAsset = await getDroppedAsset(credentials);

const { dailyCheckIns, overallTally } = droppedAsset.dataObject;

const newGoal = parseInt(req.body.goal as string);

await droppedAsset.updateDataObject({ goal: newGoal });
await droppedAsset.updateDataObject(
{ goal: newGoal },
{
analytics: [
{
analyticName: "new_configurations",
uniqueKey: profileId,
},
],
},
);

const stage = getStage(overallTally || 0, newGoal);
const newImageSrc = getImageSrc(stage);
Expand Down
Loading