mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
refactor: rename owner to createdBy
This commit is contained in:
@@ -137,16 +137,16 @@ describe('AttachmentController', () => {
|
||||
name: attachmentFile.originalname,
|
||||
location: expect.stringMatching(new RegExp(`^/${name}`)),
|
||||
context: 'block_attachment',
|
||||
ownerType: 'User',
|
||||
owner: '9'.repeat(24),
|
||||
createdByRef: 'User',
|
||||
createdBy: '9'.repeat(24),
|
||||
});
|
||||
expect(result).toEqualPayload(
|
||||
[
|
||||
{
|
||||
...attachment,
|
||||
context: 'block_attachment',
|
||||
ownerType: 'User',
|
||||
owner: '9'.repeat(24),
|
||||
createdByRef: 'User',
|
||||
createdBy: '9'.repeat(24),
|
||||
},
|
||||
],
|
||||
[...IGNORED_TEST_FIELDS, 'location', 'url'],
|
||||
|
||||
@@ -150,8 +150,8 @@ export class AttachmentController extends BaseController<Attachment> {
|
||||
size: file.size,
|
||||
type: file.mimetype,
|
||||
context,
|
||||
owner: userId,
|
||||
ownerType: 'User',
|
||||
createdBy: userId,
|
||||
createdByRef: 'User',
|
||||
});
|
||||
attachments.push(attachment);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ import { IsObjectId } from '@/utils/validation-rules/is-object-id';
|
||||
|
||||
import {
|
||||
AttachmentContext,
|
||||
AttachmentOwnerType,
|
||||
AttachmentCreatedByRef,
|
||||
TAttachmentContext,
|
||||
TAttachmentOwnerType,
|
||||
TAttachmentCreatedByRef,
|
||||
} from '../types';
|
||||
|
||||
export class AttachmentMetadataDto {
|
||||
@@ -81,12 +81,12 @@ export class AttachmentMetadataDto {
|
||||
*/
|
||||
@ApiPropertyOptional({
|
||||
description: 'Attachment Owner Type',
|
||||
enum: Object.values(AttachmentOwnerType),
|
||||
enum: Object.values(AttachmentCreatedByRef),
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsIn(Object.values(AttachmentOwnerType))
|
||||
ownerType: TAttachmentOwnerType;
|
||||
@IsIn(Object.values(AttachmentCreatedByRef))
|
||||
createdByRef: TAttachmentCreatedByRef;
|
||||
|
||||
/**
|
||||
* Attachment Owner : Subscriber or User ID
|
||||
@@ -98,7 +98,7 @@ export class AttachmentMetadataDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsObjectId({ message: 'Owner must be a valid ObjectId' })
|
||||
owner: string;
|
||||
createdBy: string;
|
||||
}
|
||||
|
||||
export class AttachmentCreateDto extends AttachmentMetadataDto {
|
||||
|
||||
@@ -20,8 +20,8 @@ export const attachment: Attachment = {
|
||||
id: '65940d115178607da65c82b6',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
owner: '1',
|
||||
ownerType: 'User',
|
||||
createdBy: '1',
|
||||
createdByRef: 'User',
|
||||
};
|
||||
|
||||
export const attachmentFile: Express.Multer.File = {
|
||||
@@ -50,8 +50,8 @@ export const attachments: Attachment[] = [
|
||||
id: '65940d115178607da65c82b7',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
owner: '1',
|
||||
ownerType: 'User',
|
||||
createdBy: '1',
|
||||
createdByRef: 'User',
|
||||
},
|
||||
{
|
||||
name: 'Screenshot from 2022-03-18 08-58-15-af61e7f71281f9fd3f1ad7ad10107741c.png',
|
||||
@@ -64,7 +64,7 @@ export const attachments: Attachment[] = [
|
||||
id: '65940d115178607da65c82b8',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
owner: '1',
|
||||
ownerType: 'User',
|
||||
createdBy: '1',
|
||||
createdByRef: 'User',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -25,9 +25,9 @@ import {
|
||||
|
||||
import {
|
||||
AttachmentContext,
|
||||
AttachmentOwnerType,
|
||||
AttachmentCreatedByRef,
|
||||
TAttachmentContext,
|
||||
TAttachmentOwnerType,
|
||||
TAttachmentCreatedByRef,
|
||||
} from '../types';
|
||||
import { MIME_REGEX } from '../utilities';
|
||||
|
||||
@@ -79,20 +79,20 @@ export class AttachmentStub extends BaseSchema {
|
||||
channel?: Partial<Record<ChannelName, any>>;
|
||||
|
||||
/**
|
||||
* Object ID of the owner (depending on the owner type)
|
||||
* Object ID of the createdBy (depending on the createdBy type)
|
||||
*/
|
||||
@Prop({
|
||||
type: MongooseSchema.Types.ObjectId,
|
||||
refPath: 'ownerType',
|
||||
refPath: 'createdByRef',
|
||||
default: null,
|
||||
})
|
||||
owner: unknown;
|
||||
createdBy: unknown;
|
||||
|
||||
/**
|
||||
* Type of the owner (depending on the owner type)
|
||||
* Type of the createdBy (depending on the createdBy type)
|
||||
*/
|
||||
@Prop({ type: String, enum: Object.values(AttachmentOwnerType) })
|
||||
ownerType: TAttachmentOwnerType;
|
||||
@Prop({ type: String, enum: Object.values(AttachmentCreatedByRef) })
|
||||
createdByRef: TAttachmentCreatedByRef;
|
||||
|
||||
/**
|
||||
* Context of the attachment
|
||||
@@ -142,20 +142,20 @@ export class AttachmentStub extends BaseSchema {
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class Attachment extends AttachmentStub {
|
||||
@Transform(({ obj }) => obj.owner?.toString() || null)
|
||||
owner: string | null;
|
||||
@Transform(({ obj }) => obj.createdBy?.toString() || null)
|
||||
createdBy: string | null;
|
||||
}
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class UserAttachmentFull extends AttachmentStub {
|
||||
@Type(() => User)
|
||||
owner: User | undefined;
|
||||
createdBy: User | undefined;
|
||||
}
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class SubscriberAttachmentFull extends AttachmentStub {
|
||||
@Type(() => Subscriber)
|
||||
owner: Subscriber | undefined;
|
||||
createdBy: Subscriber | undefined;
|
||||
}
|
||||
|
||||
export type AttachmentDocument = THydratedDocument<Attachment>;
|
||||
@@ -182,4 +182,4 @@ export type AttachmentPopulate = keyof TFilterPopulateFields<
|
||||
AttachmentStub
|
||||
>;
|
||||
|
||||
export const ATTACHMENT_POPULATE: AttachmentPopulate[] = ['owner'];
|
||||
export const ATTACHMENT_POPULATE: AttachmentPopulate[] = ['createdBy'];
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
import { Readable, Stream } from 'stream';
|
||||
|
||||
/**
|
||||
* Defines the types of owners for an attachment,
|
||||
* Defines the types of createdBys for an attachment,
|
||||
* indicating whether the file belongs to a User or a Subscriber.
|
||||
*/
|
||||
export enum AttachmentOwnerType {
|
||||
export enum AttachmentCreatedByRef {
|
||||
User = 'User',
|
||||
Subscriber = 'Subscriber',
|
||||
}
|
||||
|
||||
export type TAttachmentOwnerType = `${AttachmentOwnerType}`;
|
||||
export type TAttachmentCreatedByRef = `${AttachmentCreatedByRef}`;
|
||||
|
||||
/**
|
||||
* Defines the various contexts in which an attachment can exist.
|
||||
|
||||
Reference in New Issue
Block a user