-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d54a7d
commit 9a94568
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @param {{app: import('@slack/bolt').App, prisma: import('@prisma/client').PrismaClient}} param1 | ||
*/ | ||
module.exports = async function ({ app, prisma }) { | ||
app.command("/useroptout-library", async ({ command, body, ack, respond }) => { | ||
await ack(); | ||
const userId = body.user_id; | ||
const userRecord = await prisma.user.findFirst({ | ||
where: { | ||
id: userId, | ||
}, | ||
}); | ||
if (!userRecord) { | ||
await prisma.user.create({ | ||
data: { | ||
id: userId, | ||
optout: true, | ||
}, | ||
}); | ||
return await respond( | ||
"You've been opted out. Run the command again to opt in.", | ||
); | ||
} | ||
else if (userRecord.optout) { | ||
await prisma.user.update({ | ||
where: { | ||
id: userId, | ||
}, | ||
data: { | ||
optout: false, | ||
}, | ||
}); | ||
return await respond( | ||
"You've been opted in. Run the command again to opt out.", | ||
); | ||
} | ||
|
||
else { | ||
await prisma.user.update({ | ||
where: { | ||
id: userId, | ||
}, | ||
data: { | ||
optout: true, | ||
}, | ||
}); | ||
return await respond( | ||
"You've been opted out. Run the command again to opt in.", | ||
); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ model User { | |
createdAt DateTime @default(now()) | ||
lat String? | ||
lon String? | ||
optout Boolean @default(false) | ||
} |