Skip to content

Commit

Permalink
Add script to markbounced #518
Browse files Browse the repository at this point in the history
  • Loading branch information
mdirolf committed May 24, 2024
1 parent 6deff62 commit 2ac8ae5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
31 changes: 0 additions & 31 deletions app/pages/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ const PuzzleListItem = (props: PuzzleResult) => {
};

export default requiresAdmin(() => {
const [uidToUnsub, setUidToUnsub] = useState('');
const [donationEmail, setDonationEmail] = useState('');
const [donationAmount, setDonationAmount] = useState('');
const [donationReceivedAmount, setDonationReceivedAmount] = useState('');
Expand Down Expand Up @@ -465,36 +464,6 @@ export default requiresAdmin(() => {
<h4 className="borderBottom1pxSolidBlack">Upcoming Minis</h4>

<UpcomingMinisCalendar disableExisting={false} onChange={goToPuzzle} />
<h4 className="borderBottom1pxSolidBlack">Unsubscribe User</h4>
<form
onSubmit={logAsyncErrors(async (e: React.FormEvent) => {
e.preventDefault();
const toSubmit = uidToUnsub.trim();
setUidToUnsub('');
if (toSubmit) {
await setDoc(
getDocRef('prefs', uidToUnsub),
{ unsubs: arrayUnion('all') },
{ merge: true }
).then(() => {
showSnackbar('Unsubscribed');
});
}
})}
>
<label>
Unsubscribe by user id:
<input
className="margin0-0-5em"
type="text"
value={uidToUnsub}
onChange={(e) => {
setUidToUnsub(e.target.value);
}}
/>
</label>
<Button type="submit" text="Unsubscribe" />
</form>
<h4 className="borderBottom1pxSolidBlack">Record Donation</h4>
<form
onSubmit={logAsyncErrors(async (e: React.FormEvent) => {
Expand Down
41 changes: 41 additions & 0 deletions app/scripts/markBounced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env -S NODE_OPTIONS='--loader ts-node/esm --experimental-specifier-resolution=node' npx ts-node-script

import { getAuth } from 'firebase-admin/auth';
import { getFirestore } from 'firebase-admin/firestore';
import { getAdminApp } from '../lib/firebaseAdminWrapper';

if (process.argv.length !== 3) {
throw Error(
'Invalid use of markBounced. Usage: ./scripts/markBounced.ts [email]'
);
}

export async function markBounced() {
const emailToUnsub = process.argv[2]?.trim();
if (!emailToUnsub) {
console.error('missing email');
return;
}

const db = getFirestore(getAdminApp());

await getAuth()
.getUserByEmail(emailToUnsub)
.then((user) =>
db
.collection('prefs')
.doc(user.uid)
.set({ bounced: true }, { merge: true })
)
.catch((error: unknown) => {
console.error('error setting bounced', error);
});
}

markBounced()
.then(() => {
console.log('Done');
})
.catch((e: unknown) => {
console.error(e);
});

0 comments on commit 2ac8ae5

Please sign in to comment.