mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-10 19:57:43 +02:00
Fix peers (#120)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -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"
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user