Skip to content

Commit

Permalink
🔊 Publish user api log
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Sep 13, 2024
1 parent 2a14b68 commit 07d8092
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/server/api/routes/users/v2/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
walletUserCollection,
} = require('../../../../modules/firebase');
const { authenticateV2Login } = require('../../../middleware/auth');
const { publisher, PUBSUB_TOPIC_MISC } = require('../../../../modules/pubsub');
const {
AUTH_COOKIE_NAME,
AUTH_COOKIE_OPTION,
Expand Down Expand Up @@ -100,6 +101,21 @@ router.post('/login', async (req, res, next) => {
}
return { isNew };
});
if (result.isNew) {
publisher.publish(PUBSUB_TOPIC_MISC, req, {
logType: 'UserSignUp',
signMethod,
loginMethod,
user: userId,
});
} else {
publisher.publish(PUBSUB_TOPIC_MISC, req, {
logType: 'UserLogin',
signMethod,
loginMethod,
user: userId,
});
}
res.json(result);
return;
} catch (error) {
Expand Down
24 changes: 21 additions & 3 deletions src/server/api/routes/users/v2/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
const { authenticateV2Login } = require('../../../middleware/auth');
const { handleRestfulError } = require('../../../middleware/error');
const { sendEmail } = require('../../../../modules/sendgrid');
const { publisher, PUBSUB_TOPIC_MISC } = require('../../../../modules/pubsub');
const { isValidFollowee } = require('../../../util/cosmos');

const {
Expand Down Expand Up @@ -95,6 +96,16 @@ router.post('/email', authenticateV2Login, async (req, res, next) => {
}
);
});

publisher.publish(PUBSUB_TOPIC_MISC, req, {
logType: 'UserEmailUpdate',
email,
user,
followee,
classId,
paymentId,
});

const qsPayload = { wallet: user };
if (isValidFollowee(user, followee)) {
qsPayload.followee = followee;
Expand Down Expand Up @@ -155,12 +166,12 @@ router.put('/email', async (req, res, next) => {
if (!userDoc.exists) {
throw new Error('USER_NOT_FOUND');
}
const { emailUnconfirmed: email, emailVerifyToken } = userDoc.data();
const { emailUnconfirmed, emailVerifyToken } = userDoc.data();
if (emailVerifyToken !== token) {
throw new Error('INVALID_TOKEN');
}
const payload = {
email,
email: emailUnconfirmed,
emailUnconfirmed: FieldValue.delete(),
emailVerifyToken: FieldValue.delete(),
notification: {
Expand All @@ -172,7 +183,7 @@ router.put('/email', async (req, res, next) => {
payload.followees = FieldValue.arrayUnion(followee);
}
t.update(userRef, payload);
return email;
return emailUnconfirmed;
});

const legacyQuery = nftMintSubscriptionCollection
Expand All @@ -194,6 +205,13 @@ router.put('/email', async (req, res, next) => {
querySnapshot = await legacyQuery.get();
}

publisher.publish(PUBSUB_TOPIC_MISC, req, {
logType: 'UserEmailVerified',
email,
user,
followee,
});

res.json({ email });
} catch (error) {
switch (error.message) {
Expand Down
8 changes: 8 additions & 0 deletions src/server/api/routes/users/v2/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
} = require('../../../middleware/auth');
const { handleRestfulError } = require('../../../middleware/error');
const { walletUserCollection } = require('../../../../modules/firebase');
const { publisher, PUBSUB_TOPIC_MISC } = require('../../../../modules/pubsub');

const router = Router();

Expand Down Expand Up @@ -52,6 +53,13 @@ router.post(
}

await walletUserCollection.doc(user).update({ notification: payload });

publisher.publish(PUBSUB_TOPIC_MISC, req, {
logType: 'UserNotificationSettingUpdate',
user,
transfer,
purchasePrice,
});
res.sendStatus(200);
} catch (err) {
handleRestfulError(req, res, next, err);
Expand Down

0 comments on commit 07d8092

Please sign in to comment.