Fix peers (#120)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2025-10-24 17:08:10 +04:00
committed by GitHub
parent c36775417b
commit abaf500ea9
8 changed files with 61 additions and 6 deletions
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@hcengineering/communication-cockroach",
"comment": "Fix peer create",
"type": "patch"
}
],
"packageName": "@hcengineering/communication-cockroach"
}
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@hcengineering/communication-sdk-types",
"comment": "Fix peer create event",
"type": "patch"
}
],
"packageName": "@hcengineering/communication-sdk-types"
}
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@hcengineering/communication-server",
"comment": "Fix peer create",
"type": "patch"
}
],
"packageName": "@hcengineering/communication-server"
}
+3 -2
View File
@@ -233,9 +233,10 @@ export class CockroachAdapter implements DbAdapter {
kind: PeerKind,
value: string,
extra: PeerExtra,
date: Date
date: Date,
options?: {newValue?: boolean}
): Promise<void> {
await this.peer.createPeer(workspaceId, cardId, kind, value, extra, date)
await this.peer.createPeer(workspaceId, cardId, kind, value, extra, date, options)
}
async removePeer (workspaceId: WorkspaceUuid,
+18 -3
View File
@@ -35,7 +35,8 @@ export class PeersDb extends BaseDb {
kind: PeerKind,
value: string,
extra: PeerExtra,
date: Date
date: Date,
options?: { newValue?: boolean }
): Promise<void> {
const db: DbModel<Domain.Peer> = {
workspace_id: workspaceId,
@@ -45,8 +46,22 @@ export class PeersDb extends BaseDb {
extra,
created: date
}
const { sql, values } = this.getInsertSql(Domain.Peer, db, [])
await this.execute(sql, values, 'insert peer')
if (options?.newValue === true) {
const { sql, values } = this.getInsertSql(Domain.Peer, db, [], {
conflictColumns: ['workspace_id', 'kind', 'value'],
conflictAction: 'DO NOTHING'
})
const result = await this.execute(sql, values, 'insert peer')
const count = result?.count ?? 0
if (count === 0) {
throw Error('Peer value already exists')
}
} else {
const { sql, values } = this.getInsertSql(Domain.Peer, db, [])
await this.execute(sql, values, 'insert peer')
}
}
async removePeer (workspaceId: WorkspaceUuid, cardId: CardID, kind: PeerKind, value: string): Promise<void> {
+2 -1
View File
@@ -70,7 +70,8 @@ export interface DbAdapter {
kind: PeerKind,
value: string,
extra: PeerExtra,
date: Date
date: Date,
options?: {newValue?: boolean}
) => Promise<void>
removePeer: (workspaceId: WorkspaceUuid,
cardId: CardID,
+3
View File
@@ -31,6 +31,9 @@ export interface CreatePeerEvent extends BaseEvent {
kind: PeerKind
value: string
extra?: PeerExtra
options?: {
newValue?: boolean
}
date?: Date
}
@@ -457,6 +457,11 @@ const CreatePeerEventSchema = BaseEventSchema.extend({
kind: z.string().nonempty(),
value: z.string().nonempty(),
extra: z.record(z.any()).optional(),
options: z
.object({
newValue: z.boolean().optional()
})
.optional(),
date: DateSchema
}).strict()