feat: last edited by uuid

This commit is contained in:
Mo
2023-05-25 14:01:32 -05:00
parent 86dbfda80a
commit 829bdf96ce
9 changed files with 35 additions and 7 deletions
@@ -13,9 +13,19 @@ export class AddGroupUuidToItems1684318117584 implements MigrationInterface {
isNullable: true,
}),
)
await queryRunner.addColumn(
'items',
new TableColumn({
name: 'last_edited_by_uuid',
type: 'varchar',
length: '36',
isNullable: true,
}),
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn('items', 'group_uuid')
await queryRunner.dropColumn('items', 'last_edited_by_uuid')
}
}
@@ -81,6 +81,12 @@ export class Item {
@Index('index_items_on_user_uuid')
declare userUuid: string
@Column({
name: 'last_edited_by_uuid',
length: 36,
})
declare lastEditedByUuid: string
@Column({
type: 'tinyint',
precision: 1,
@@ -32,10 +32,14 @@ export class ItemFactory implements ItemFactoryInterface {
newItem.uuid = dto.itemHash.uuid
newItem.updatedWithSession = dto.sessionUuid
newItem.contentSize = 0
newItem.userUuid = dto.userUuid
if (dto.itemHash.content) {
newItem.content = dto.itemHash.content
}
newItem.userUuid = dto.userUuid
if (dto.itemHash.last_edited_by_uuid) {
newItem.lastEditedByUuid = dto.itemHash.last_edited_by_uuid
}
if (dto.itemHash.group_uuid) {
newItem.groupUuid = dto.itemHash.group_uuid
}
@@ -2,6 +2,7 @@ import { ContentType } from '@standardnotes/common'
export type ItemHash = {
uuid: string
user_uuid: string
content?: string
content_type: ContentType
deleted?: boolean
@@ -10,6 +11,7 @@ export type ItemHash = {
enc_item_key?: string
items_key_id?: string
group_uuid?: string
last_edited_by_uuid?: string | null
created_at?: string
created_at_timestamp?: number
updated_at?: string
@@ -133,6 +133,7 @@ export class ItemService implements ItemServiceInterface {
existingItem,
itemHash,
sessionUuid: dto.sessionUuid,
userUuid: dto.userUuid,
})
savedItems.push(updatedItem)
} else {
@@ -201,10 +202,14 @@ export class ItemService implements ItemServiceInterface {
private async updateExistingItem(dto: {
existingItem: Item
itemHash: ItemHash
userUuid: string
sessionUuid: string | null
}): Promise<Item> {
dto.existingItem.updatedWithSession = dto.sessionUuid
dto.existingItem.contentSize = 0
dto.existingItem.groupUuid = dto.itemHash.group_uuid ?? null
dto.existingItem.lastEditedByUuid = dto.userUuid
if (dto.itemHash.content) {
dto.existingItem.content = dto.itemHash.content
}
@@ -215,8 +220,6 @@ export class ItemService implements ItemServiceInterface {
dto.existingItem.deleted = dto.itemHash.deleted
}
dto.existingItem.groupUuid = dto.itemHash.group_uuid ?? null
let wasMarkedAsDuplicate = false
if (dto.itemHash.duplicate_of) {
wasMarkedAsDuplicate = !dto.existingItem.duplicateOf
@@ -8,6 +8,8 @@ export type ItemProjection = {
content_type: string
auth_hash: string | null
deleted: boolean
user_uuid: string
last_edited_by_uuid: string | null
created_at: string
created_at_timestamp: number
updated_at: string
@@ -15,10 +15,7 @@ export class ItemProjector implements ProjectorInterface<Item, ItemProjection> {
projectCustom(_projectionType: string, item: Item): ItemProjectionWithUser {
const fullProjection = this.projectFull(item)
return {
...fullProjection,
user_uuid: item.userUuid,
}
return fullProjection
}
projectFull(item: Item): ItemProjection {
@@ -37,6 +34,8 @@ export class ItemProjector implements ProjectorInterface<Item, ItemProjection> {
updated_at_timestamp: item.updatedAtTimestamp,
updated_with_session: item.updatedWithSession,
group_uuid: item.groupUuid,
user_uuid: item.userUuid,
last_edited_by_uuid: item.lastEditedByUuid,
}
}
}
@@ -9,4 +9,5 @@ export type SavedItemProjection = {
updated_at: string
updated_at_timestamp: number
group_uuid: string | null
last_edited_by_uuid: string | null
}
@@ -28,6 +28,7 @@ export class SavedItemProjector implements ProjectorInterface<Item, SavedItemPro
updated_at: this.timer.convertMicrosecondsToStringDate(item.updatedAtTimestamp),
updated_at_timestamp: item.updatedAtTimestamp,
group_uuid: item.groupUuid,
last_edited_by_uuid: item.lastEditedByUuid,
}
}
}