diff --git a/common_knowledge/Complex-Functions.md b/common_knowledge/Complex-Functions.md index f67b6e60249..0291537624d 100644 --- a/common_knowledge/Complex-Functions.md +++ b/common_knowledge/Complex-Functions.md @@ -190,14 +190,6 @@ export async function __updateComment( }); ``` - `Repository` - -```typescript - // update address last active - address.last_active = new Date(); - address.save(); -``` - `Schemas` ```typescript diff --git a/libs/model/src/comment/CreateComment.command.ts b/libs/model/src/comment/CreateComment.command.ts index 0a93333b6d4..76759b38514 100644 --- a/libs/model/src/comment/CreateComment.command.ts +++ b/libs/model/src/comment/CreateComment.command.ts @@ -89,10 +89,6 @@ export function CreateComment(): Command< }, ); - // update timestamps - address.last_active = new Date(); - await address.save({ transaction }); - thread.last_commented_on = new Date(); await thread.save({ transaction }); diff --git a/libs/model/src/comment/CreateCommentReaction.command.ts b/libs/model/src/comment/CreateCommentReaction.command.ts index 373d433f611..45e72811745 100644 --- a/libs/model/src/comment/CreateCommentReaction.command.ts +++ b/libs/model/src/comment/CreateCommentReaction.command.ts @@ -45,9 +45,6 @@ export function CreateCommentReaction(): Command< transaction, }); - address.last_active = new Date(); - await address.save({ transaction }); - return reaction.id; }, ); diff --git a/libs/model/src/comment/UpdateComment.command.ts b/libs/model/src/comment/UpdateComment.command.ts index ec9ce6d2f59..6c4fb305480 100644 --- a/libs/model/src/comment/UpdateComment.command.ts +++ b/libs/model/src/comment/UpdateComment.command.ts @@ -57,10 +57,6 @@ export function UpdateComment(): Command< { transaction }, ); - // update timestamps - address.last_active = new Date(); - await address.save({ transaction }); - mentions.length && (await emitMentions(models, transaction, { authorAddressId: address.id!, diff --git a/libs/model/src/community/UpdateCommunity.command.ts b/libs/model/src/community/UpdateCommunity.command.ts index 4d4cd34d955..4d6d6c12936 100644 --- a/libs/model/src/community/UpdateCommunity.command.ts +++ b/libs/model/src/community/UpdateCommunity.command.ts @@ -1,13 +1,12 @@ import { InvalidInput, type Command } from '@hicommonwealth/core'; import * as schemas from '@hicommonwealth/schemas'; -import { ALL_COMMUNITIES, ChainBase } from '@hicommonwealth/shared'; +import { ChainBase } from '@hicommonwealth/shared'; import { models } from '../database'; import { AuthContext, isAuthorized } from '../middleware'; import { mustExist } from '../middleware/guards'; import { checkSnapshotObjectExists, commonProtocol } from '../services'; export const UpdateCommunityErrors = { - ReservedId: 'The id is reserved and cannot be used', NotAdmin: 'Not an admin', SnapshotOnlyOnEthereum: 'Snapshot data may only be added to chains with Ethereum base', @@ -47,9 +46,6 @@ export function UpdateCommunity(): Command< transactionHash, } = payload; - if (id === ALL_COMMUNITIES) - throw new InvalidInput(UpdateCommunityErrors.ReservedId); - const community = await models.Community.findOne({ where: { id }, include: [ diff --git a/libs/model/src/middleware/authorization.ts b/libs/model/src/middleware/authorization.ts index a9d3a707f35..87becaf292e 100644 --- a/libs/model/src/middleware/authorization.ts +++ b/libs/model/src/middleware/authorization.ts @@ -160,6 +160,11 @@ async function buildAuth( throw new InvalidActor(actor, `User is not ${roles} in the community`); auth.is_author = auth.address!.id === auth.author_address_id; + + // fire and forget address activity tracking + auth.address.last_active = new Date(); + void auth.address.save(); + return auth; } diff --git a/libs/model/src/thread/CreateThread.command.ts b/libs/model/src/thread/CreateThread.command.ts index 85fdc438644..10ae582141f 100644 --- a/libs/model/src/thread/CreateThread.command.ts +++ b/libs/model/src/thread/CreateThread.command.ts @@ -151,9 +151,6 @@ export function CreateThread(): Command< }, ); - address.last_active = new Date(); - await address.save({ transaction }); - await models.ThreadSubscription.create( { user_id: actor.user.id!, diff --git a/libs/model/src/thread/CreateThreadReaction.command.ts b/libs/model/src/thread/CreateThreadReaction.command.ts index 0450433aa1b..b9a14c05a46 100644 --- a/libs/model/src/thread/CreateThreadReaction.command.ts +++ b/libs/model/src/thread/CreateThreadReaction.command.ts @@ -53,9 +53,6 @@ export function CreateThreadReaction(): Command< transaction, }); - address.last_active = new Date(); - await address.save({ transaction }); - return reaction.id; }, ); diff --git a/libs/model/test/community/community-lifecycle.spec.ts b/libs/model/test/community/community-lifecycle.spec.ts index 6b35f7abfa5..91d4c2cbc16 100644 --- a/libs/model/test/community/community-lifecycle.spec.ts +++ b/libs/model/test/community/community-lifecycle.spec.ts @@ -6,7 +6,7 @@ import { dispose, query, } from '@hicommonwealth/core'; -import { ALL_COMMUNITIES, ChainBase, ChainType } from '@hicommonwealth/shared'; +import { ChainBase, ChainType } from '@hicommonwealth/shared'; import { Chance } from 'chance'; import { afterAll, assert, beforeAll, describe, expect, test } from 'vitest'; import { @@ -241,20 +241,6 @@ describe('Community lifecycle', () => { assert.equal(updated?.type, 'chain'); }); - test('should throw if id is reserved', async () => { - await expect(() => - command(UpdateCommunity(), { - actor: superAdminActor, - payload: { - ...baseRequest, - id: ALL_COMMUNITIES, - namespace: 'tempNamespace', - chain_node_id: 1263, - }, - }), - ).rejects.toThrow(); - }); - test('should throw if snapshot not found', async () => { await expect(() => command(UpdateCommunity(), { diff --git a/libs/schemas/src/commands/community.schemas.ts b/libs/schemas/src/commands/community.schemas.ts index 06089a86131..885b79526f7 100644 --- a/libs/schemas/src/commands/community.schemas.ts +++ b/libs/schemas/src/commands/community.schemas.ts @@ -130,6 +130,16 @@ export const UpdateCommunity = { .partial() .extend({ id: z.string(), + name: z + .string() + .max(255) + .regex(COMMUNITY_NAME_REGEX, { + message: COMMUNITY_NAME_ERROR, + }) + .refine((data) => !data.includes(ALL_COMMUNITIES), { + message: `String must not contain '${ALL_COMMUNITIES}'`, + }) + .optional(), featuredTopics: z.array(z.string()).optional(), snapshot: Snapshot.or(z.array(Snapshot)).optional(), transactionHash: z.string().optional(),