Skip to content

Commit

Permalink
Fixed profile count
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisassad authored and ilijabojanovic committed Nov 19, 2024
1 parent 6f9ef5b commit ed799f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
9 changes: 4 additions & 5 deletions libs/model/src/community/JoinCommunity.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as schemas from '@hicommonwealth/schemas';
import { ChainBase, addressSwapper } from '@hicommonwealth/shared';
import { models } from '../database';
import { mustExist } from '../middleware/guards';
import { incrementProfileCount } from '../utils';
import { findCompatibleAddress } from '../utils/findBaseAddress';

export const JoinCommunityErrors = {
Expand Down Expand Up @@ -102,11 +101,11 @@ export function JoinCommunity(): Command<typeof schemas.JoinCommunity> {
{ transaction },
);

await incrementProfileCount(
community.id,
actor.user.id!,
await models.Community.increment('profile_count', {
by: 1,
where: { id: community_id },
transaction,
);
});

return created.id!;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.query(`
UPDATE "Communities" C
SET profile_count = (SELECT COUNT(DISTINCT (user_id)) FROM "Addresses" WHERE community_id = C.id);
`);
},

async down(queryInterface, Sequelize) {},
};
9 changes: 9 additions & 0 deletions packages/commonwealth/server/util/verifySessionSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ const verifySessionSignature = async (
});
if (!user || !user.id) throw new Error('Failed to create user');
addressModel.user_id = user!.id;

await addressModel.save();
return;
}
}

// user already exists but new community joined
await incrementProfileCount(
addressModel.community_id!,
addressModel.user_id!,
);
} else {
// mark the address as verified
addressModel.verification_token_expires = null;
Expand Down

0 comments on commit ed799f1

Please sign in to comment.