Files
AFFiNE-Mirror/packages/backend/server/src/models/comment-attachment.ts
T
fengmk2 45c016af8b fix(server): add user id to comment-attachment model (#13113)
close AF-2723



#### PR Dependency Tree


* **PR #13113** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Comment attachments now track and display the user who uploaded them.

* **Tests**
* Updated tests to verify that the uploader’s information is correctly
stored and retrieved with comment attachments.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-09 12:16:09 +00:00

72 lines
1.6 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { BaseModel } from './base';
export type CreateCommentAttachmentInput =
Prisma.CommentAttachmentUncheckedCreateInput;
/**
* Comment Attachment Model
*/
@Injectable()
export class CommentAttachmentModel extends BaseModel {
async upsert(input: CreateCommentAttachmentInput) {
return await this.db.commentAttachment.upsert({
where: {
workspaceId_docId_key: {
workspaceId: input.workspaceId,
docId: input.docId,
key: input.key,
},
},
update: {
name: input.name,
mime: input.mime,
size: input.size,
},
create: {
workspaceId: input.workspaceId,
docId: input.docId,
key: input.key,
name: input.name,
mime: input.mime,
size: input.size,
createdBy: input.createdBy,
},
});
}
async delete(workspaceId: string, docId: string, key: string) {
await this.db.commentAttachment.deleteMany({
where: {
workspaceId,
docId,
key,
},
});
this.logger.log(`deleted comment attachment ${workspaceId}/${key}`);
}
async get(workspaceId: string, docId: string, key: string) {
return await this.db.commentAttachment.findUnique({
where: {
workspaceId_docId_key: {
workspaceId,
docId,
key,
},
},
});
}
async list(workspaceId: string, docId?: string) {
return await this.db.commentAttachment.findMany({
where: {
workspaceId,
docId,
},
});
}
}