|
|
|
@ -358,38 +358,61 @@ fastify.post('/addActivity', async (request, reply) => { |
|
|
|
&& "title" in content |
|
|
|
&& "desc" in content |
|
|
|
&& "start" in content |
|
|
|
&& "end" in content |
|
|
|
&& "where" in content) { |
|
|
|
let activityUid = makeid(16); |
|
|
|
if (["event", "treasure"].contains(content.type)) { |
|
|
|
let activityUid = makeid(16); |
|
|
|
if ("activityUid" in content) { |
|
|
|
let activityExists = check(content, "activityUid", ActivityData) |
|
|
|
if (activityExists.success) { |
|
|
|
activityUid = content.activityUid; |
|
|
|
if ("activityUid" in content) { |
|
|
|
let activityExists = check(content, "activityUid", ActivityData) |
|
|
|
if (activityExists.success) { |
|
|
|
activityUid = content.activityUid; |
|
|
|
} else { |
|
|
|
return activityExists; |
|
|
|
} |
|
|
|
} |
|
|
|
switch (content.type) { |
|
|
|
case "event": |
|
|
|
if ("end" in content) { |
|
|
|
ActivityData[activityUid] = { |
|
|
|
type: content.type, |
|
|
|
title: content.title, |
|
|
|
desc: content.desc, |
|
|
|
start: content.start, |
|
|
|
end: content.end, |
|
|
|
where: content.where, |
|
|
|
} |
|
|
|
saveData(activityPath, ActivityData); |
|
|
|
return { |
|
|
|
sucess: true, |
|
|
|
uid: activityUid, |
|
|
|
activity: ActivityData[activityUid] |
|
|
|
} |
|
|
|
} else { |
|
|
|
return activityExists; |
|
|
|
return { |
|
|
|
success: false, |
|
|
|
why: "Missing end" |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
case "treasure": |
|
|
|
ActivityData[activityUid] = { |
|
|
|
type: content.type, |
|
|
|
title: content.title, |
|
|
|
desc: content.desc, |
|
|
|
start: content.start, |
|
|
|
where: content.where, |
|
|
|
treasureState: "Pending" |
|
|
|
} |
|
|
|
saveData(activityPath, ActivityData); |
|
|
|
return { |
|
|
|
sucess: true, |
|
|
|
uid: activityUid, |
|
|
|
activity: ActivityData[activityUid] |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
return { |
|
|
|
success: false, |
|
|
|
why: "Unkonw type" |
|
|
|
} |
|
|
|
} |
|
|
|
ActivityData[activityUid] = { |
|
|
|
type: content.type, |
|
|
|
title: content.title, |
|
|
|
desc: content.desc, |
|
|
|
start: content.start, |
|
|
|
end: content.end, |
|
|
|
where: content.where |
|
|
|
} |
|
|
|
saveData(activityPath, ActivityData); |
|
|
|
return { |
|
|
|
sucess: true, |
|
|
|
uid: activityUid, |
|
|
|
activity: ActivityData[activityUid] |
|
|
|
} |
|
|
|
} else { |
|
|
|
return { |
|
|
|
success: false, |
|
|
|
why: "Unkonw type" |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
return { |
|
|
|
@ -515,6 +538,8 @@ fastify.post('/acceptTreasure', async (request, reply) => { |
|
|
|
if (treasureExists.success) { |
|
|
|
TreasureData[content.treasureUid].state = "Accepted"; |
|
|
|
saveData(treasurePath, TreasureData); |
|
|
|
ActivityData[GoldenUsers[activityUid].activityUid].treasureState = "Accepted"; |
|
|
|
saveData(activityPath, ActivityData); |
|
|
|
GoldenUsers[TreasureData[content.treasureUid].activityUid] = { |
|
|
|
userUid: TreasureData[content.treasureUid].creator, |
|
|
|
activityUid: TreasureData[content.treasureUid].activityUid |
|
|
|
|