Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: assign random dice side when null #49

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 4 additions & 9 deletions services/rest/paths/pick-idea/pick-idea.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ export async function handlePickIdea(response) {
* @returns {Promise<{error: string}|{idea: dbIdea}|{idea:Idea}>}
*/
async function pickIdea() {
let { focusGroup, topic, medium } = getAllLabelsForCurrentSides();
const { focusGroup, topic, medium } = getAllLabelsForCurrentSides();

if (!focusGroup || !topic || !medium) {
const errorMessage = `Some dices have not set a side yet: ${JSON.stringify({ focusGroup, topic, medium })}`;
console.error(errorMessage);

focusGroup = focusGroup || getLabelFromSide(`A${getRandomNumber(1, 6)}`);
topic = topic || getLabelFromSide(`B${getRandomNumber(1, 6)}`);
medium = medium || getLabelFromSide(`C${getRandomNumber(1, 6)}`);
}
console.log({ focusGroup });
console.log({ topic });
console.log({ medium });

const { data, error } = await supabase
.from("pregenerated_ideas")
Expand Down
28 changes: 20 additions & 8 deletions services/state/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,25 @@ export function getAllLabelsForSides({ A, B, C }) {
* @returns {{focusGroup: string[], topic: string[], medium: string[]}}
*/
export function getAllLabelsForCurrentSides() {
// if (dices.A.side === null || dices.B.side === null || dices.C.side === null) {
// return {
// focusGroup: dices.A.side,
// topic: dices.B.side,
// medium: dices.C.side,
// };
// }
aeschi marked this conversation as resolved.
Show resolved Hide resolved

if (dices.A.side === null || dices.B.side === null || dices.C.side === null) {
return {
focusGroup: dices.A.side,
topic: dices.B.side,
medium: dices.C.side,
};
const errorMessage = `Some dices have not set a side yet: ${JSON.stringify(dices.A.side, dices.B.side, dices.C.side)}`;
console.error(errorMessage);
}

const A = `A${dices.A.side}`;
const B = `B${dices.B.side}`;
const C = `C${dices.C.side}`;
const A = dices.A.side ? `A${dices.A.side}` : `A${getRandomNumber(1, 6)}`;
const B = dices.B.side ? `B${dices.B.side}` : `B${getRandomNumber(1, 6)}`;
const C = dices.C.side ? `C${dices.C.side}` : `C${getRandomNumber(1, 6)}`;

console.log(A, B, C);

const focusGroup = getLabelFromSide(A);
const topic = getLabelFromSide(B);
const medium = getLabelFromSide(C);
Expand All @@ -222,3 +230,7 @@ export function setLabels(newLabels) {
console.error(error);
}
}

function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}