Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/services/chatter-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ interface ChatterMention {
id?: string | number;
}

/**
* Server-side-only overrides for `postMessage`. Not part of `PostChatterMessageDto`, so
* nothing here is settable over HTTP - only in-process callers such as migration or
* back-fill services can supply it.
*/
export interface PostChatterMessageOptions {
/** Backdate the message instead of stamping it with the current time. */
createdAt?: Date;
}

@Injectable()
export class ChatterMessageService extends CRUDService<ChatterMessage> {
private readonly _logger = new Logger(ChatterMessageService.name);
Expand Down Expand Up @@ -389,7 +399,14 @@ export class ChatterMessageService extends CRUDService<ChatterMessage> {
return this.trimMessageUser(savedMessage);
}

async postMessage(postDto: PostChatterMessageDto, files: Express.Multer.File[] = []) {
/**
* Post a chatter message.
*
* `options` is deliberately kept out of `PostChatterMessageDto` so it can only be supplied
* by server-side callers (migrations, back-fills). The controller binds the DTO alone, so
* an API client has no way to backdate a message.
*/
async postMessage(postDto: PostChatterMessageDto, files: Express.Multer.File[] = [], options: PostChatterMessageOptions = {}) {
const coModelName = lowerFirst(postDto.coModelName);
await this.assertRecordAccess(coModelName, postDto.coModelEntityId);

Expand All @@ -404,6 +421,10 @@ export class ChatterMessageService extends CRUDService<ChatterMessage> {
chatterMessage.coModelEntityId = postDto.coModelEntityId;
chatterMessage.coModelName = coModelName;
chatterMessage.modelUserKey = postDto.modelUserKey ?? null;
// Left unset otherwise, so the @CreateDateColumn default still applies.
if (options.createdAt) {
chatterMessage.createdAt = options.createdAt;
}

const model = await this.modelMetadataRepo.findOne({
where: { singularName: coModelName },
Expand Down