@ossy/booking 3.19.0 → 3.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -50,7 +50,7 @@ Resource schemas live in `src/*.schema.js` and are auto-discovered by `@ossy/app
50
50
 
51
51
  Documents are stored under canonical locations. Import paths from `@ossy/booking` (`services`, `bookings`, `availability`).
52
52
 
53
- Tasks write resources via `commitResource` / `mutateResource` from `@ossy/resources/server`, using `schemaId` on resource events (ADR 0008).
53
+ Tasks write resources via `ResourceStream.commit` / `ResourceStream.mutate`, using `schemaId` on resource events (ADR 0008).
54
54
 
55
55
  ## Projections
56
56
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/booking",
3
3
  "description": "Booking feature package — services, availability, and appointment management for Ossy providers",
4
- "version": "3.19.0",
4
+ "version": "3.20.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "module": "./src/index.js",
@@ -16,12 +16,12 @@
16
16
  "dependencies": {
17
17
  "@ossy/config": "^3.0.9",
18
18
  "@ossy/email": "^3.11.0",
19
- "@ossy/event-store": "^3.19.0",
19
+ "@ossy/event-store": "^3.20.0",
20
20
  "@ossy/observability": "^3.0.9",
21
- "@ossy/platform": "^3.19.0",
22
- "@ossy/resources": "^3.19.0",
23
- "@ossy/users": "^3.18.0",
24
- "@ossy/workspaces": "^3.18.0"
21
+ "@ossy/platform": "^3.20.0",
22
+ "@ossy/resources": "^3.20.0",
23
+ "@ossy/users": "^3.20.0",
24
+ "@ossy/workspaces": "^3.20.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@ossy/app": ">=1.0.0",
@@ -38,5 +38,5 @@
38
38
  "/src",
39
39
  "README.md"
40
40
  ],
41
- "gitHead": "0ac103001a468f56597c02cf1c6802bf7bd89b33"
41
+ "gitHead": "edab6a966f41c07a68bdd86f3864cc2ad02e3406"
42
42
  }
@@ -3,8 +3,8 @@ import { ResourcesQueries } from '@ossy/resources/server'
3
3
  /**
4
4
  * List booking resources by schema id (and optional workspace).
5
5
  */
6
- export function getBookingResources ({ schemaId, belongsTo }) {
6
+ export function getBookingResources ({ schemaId, belongsTo, user }) {
7
7
  const query = { type: schemaId }
8
8
  if (belongsTo) query.belongsTo = belongsTo
9
- return ResourcesQueries.GetResources(query)
9
+ return ResourcesQueries.GetResources(query, user)
10
10
  }
@@ -1,18 +1,29 @@
1
- import { ResourcesEvents, mutateResource, viewResource } from '@ossy/resources/server'
1
+ import { GetResource, PatchResourceContent } from '@ossy/resources'
2
2
  import BookingCancellationEmail from './booking-cancellation.email.jsx'
3
3
 
4
4
  export const metadata = { id: '@ossy/booking/tasks/cancel' }
5
5
 
6
- export async function run ({ payload, req, log, integrations }) {
6
+ async function loadBooking (sdk, bookingId) {
7
+ try {
8
+ const booking = await sdk.invoke(GetResource, { resourceId: bookingId })
9
+ if (!booking?.id) throw Object.assign(new Error('Booking not found'), { status: 404 })
10
+ return booking
11
+ } catch (err) {
12
+ if (err?.status === 404) throw Object.assign(new Error('Booking not found'), { status: 404 })
13
+ throw err
14
+ }
15
+ }
16
+
17
+ export async function run ({ payload, req, log, integrations, sdk }) {
7
18
  const bookingId = payload?.bookingId ?? req?.params?.bookingId
8
19
  const workspaceId = payload?.workspaceId ?? req?.workspaceId
9
20
 
10
21
  if (!bookingId) throw Object.assign(new Error('bookingId is required'), { status: 400 })
22
+ if (!sdk?.invoke) throw Object.assign(new Error('sdk is required'), { status: 500 })
11
23
 
12
24
  log?.info(`[booking/tasks/cancel] Cancelling booking ${bookingId}`)
13
25
 
14
- const booking = await viewResource(bookingId)
15
- if (!booking?.id) throw Object.assign(new Error('Booking not found'), { status: 404 })
26
+ const booking = await loadBooking(sdk, bookingId)
16
27
 
17
28
  if (booking.belongsTo !== workspaceId) {
18
29
  throw Object.assign(new Error('You do not have permission to cancel this booking'), { status: 403 })
@@ -22,15 +33,10 @@ export async function run ({ payload, req, log, integrations }) {
22
33
  throw Object.assign(new Error('Booking is already cancelled'), { status: 409 })
23
34
  }
24
35
 
25
- await mutateResource(
26
- bookingId,
27
- ResourcesEvents.Patched({
28
- createdBy: req?.userId ?? 'system',
29
- // Required for BookingListProjection.scopeFromEvent (live projection updates).
30
- belongsTo: booking.belongsTo,
31
- content: { ...booking.content, status: 'cancelled' },
32
- }),
33
- )
36
+ await sdk.invoke(PatchResourceContent, {
37
+ resourceId: bookingId,
38
+ content: { status: 'cancelled' },
39
+ })
34
40
 
35
41
  log?.info(`[booking/tasks/cancel] Booking ${bookingId} cancelled`)
36
42
 
@@ -39,9 +39,16 @@ export default {
39
39
 
40
40
  // Catalog service
41
41
  { action: OpenServices },
42
- { result: { selector: '[data-services-status]', timeout: 15000 } },
42
+ {
43
+ result: {
44
+ selector: '[data-services-status="empty"], [data-services-status="populated"]',
45
+ timeout: 20000,
46
+ },
47
+ },
48
+ { press: 'Escape' },
43
49
  { result: { action: OpenCreateService, timeout: 10000 } },
44
50
  { action: OpenCreateService },
51
+ { result: { selector: '[data-services-form="open"]', timeout: 10000 } },
45
52
  { result: { action: CreateService, timeout: 15000 } },
46
53
  { form: ServiceForm },
47
54
  { action: CreateService },
@@ -1,22 +1,33 @@
1
- import { ResourcesEvents, mutateResource, viewResource } from '@ossy/resources/server'
1
+ import { GetResource, PatchResourceContent } from '@ossy/resources'
2
2
  import BookingConfirmationEmail, { id as bookingConfirmationEmailId } from './booking-confirmation.email.jsx'
3
3
  import { resolveProviderName, workspaceIdFromContent } from './provider-fields.js'
4
4
  import { resolveWorkspaceContact } from './resolve-workspace-contact.js'
5
5
 
6
6
  export const metadata = { id: '@ossy/booking/tasks/confirm' }
7
7
 
8
- export async function run ({ payload, req, log, integrations }) {
8
+ async function loadBooking (sdk, bookingId) {
9
+ try {
10
+ const booking = await sdk.invoke(GetResource, { resourceId: bookingId })
11
+ if (!booking?.id) throw Object.assign(new Error('Booking not found'), { status: 404 })
12
+ return booking
13
+ } catch (err) {
14
+ if (err?.status === 404) throw Object.assign(new Error('Booking not found'), { status: 404 })
15
+ throw err
16
+ }
17
+ }
18
+
19
+ export async function run ({ payload, req, log, integrations, sdk }) {
9
20
  const bookingId = payload?.bookingId ?? req?.params?.bookingId
10
21
  const workspaceId = payload?.workspaceId ?? req?.workspaceId
11
22
  const providerName = resolveProviderName(payload ?? {})
12
23
  const { baseUrl } = payload ?? {}
13
24
 
14
25
  if (!bookingId) throw Object.assign(new Error('bookingId is required'), { status: 400 })
26
+ if (!sdk?.invoke) throw Object.assign(new Error('sdk is required'), { status: 500 })
15
27
 
16
28
  log?.info(`[booking/tasks/confirm] Confirming booking ${bookingId}`)
17
29
 
18
- const booking = await viewResource(bookingId)
19
- if (!booking?.id) throw Object.assign(new Error('Booking not found'), { status: 404 })
30
+ const booking = await loadBooking(sdk, bookingId)
20
31
 
21
32
  if (booking.belongsTo !== workspaceId) {
22
33
  throw Object.assign(new Error('You do not have permission to confirm this booking'), { status: 403 })
@@ -29,15 +40,10 @@ export async function run ({ payload, req, log, integrations }) {
29
40
  )
30
41
  }
31
42
 
32
- await mutateResource(
33
- bookingId,
34
- ResourcesEvents.Patched({
35
- createdBy: req?.userId ?? 'system',
36
- // Required for BookingListProjection.scopeFromEvent (live projection updates).
37
- belongsTo: booking.belongsTo,
38
- content: { ...booking.content, status: 'confirmed' },
39
- }),
40
- )
43
+ await sdk.invoke(PatchResourceContent, {
44
+ resourceId: bookingId,
45
+ content: { status: 'confirmed' },
46
+ })
41
47
 
42
48
  log?.info(`[booking/tasks/confirm] Booking ${bookingId} confirmed`)
43
49
 
@@ -1,6 +1,6 @@
1
1
  import { nanoid } from 'nanoid'
2
2
  import { ConfigService } from '@ossy/config'
3
- import { ResourcesEvents, commitResource } from '@ossy/resources/server'
3
+ import { ResourceStream, ResourcesEvents } from '@ossy/resources/server'
4
4
  import { BookingSchema } from './schema-ids.js'
5
5
  import { getAvailableSlots } from './availability-engine.js'
6
6
  import { toMs } from './time.js'
@@ -52,6 +52,7 @@ export async function run({ payload, req, log, integrations }) {
52
52
  const availabilityResources = await getBookingResources({
53
53
  schemaId: BookingSchema.availability,
54
54
  belongsTo: workspaceId,
55
+ user: ResourceStream.system('booking-create'),
55
56
  })
56
57
 
57
58
  // New format: single resource with weeklyWindows array in content
@@ -83,6 +84,7 @@ export async function run({ payload, req, log, integrations }) {
83
84
  const allBookingResources = await getBookingResources({
84
85
  schemaId: BookingSchema.booking,
85
86
  belongsTo: workspaceId,
87
+ user: ResourceStream.system('booking-create'),
86
88
  })
87
89
 
88
90
  const confirmedBookings = allBookingResources
@@ -139,7 +141,7 @@ export async function run({ payload, req, log, integrations }) {
139
141
  },
140
142
  })
141
143
 
142
- const booking = await commitResource(event)
144
+ const booking = await ResourceStream.commit(event, ResourceStream.system('booking-create'))
143
145
 
144
146
  log?.info(`[booking/tasks/create] Booking ${bookingId} created`)
145
147
 
@@ -1,5 +1,5 @@
1
1
  import { nanoid } from 'nanoid'
2
- import { ResourcesEvents, commitResource } from '@ossy/resources/server'
2
+ import { ResourceStream, ResourcesEvents } from '@ossy/resources/server'
3
3
  import { BookingSchema } from './schema-ids.js'
4
4
  import { services } from './locations.js'
5
5
 
@@ -40,7 +40,7 @@ export async function run ({ payload, req, log }) {
40
40
  content,
41
41
  })
42
42
 
43
- const service = await commitResource(event)
43
+ const service = await ResourceStream.commit(event, ResourceStream.actor({ req, payload }))
44
44
 
45
45
  return { id: resourceId, ...content, ...service }
46
46
  }
@@ -1,19 +1,30 @@
1
- import { ResourcesEvents, mutateResource, viewResource } from '@ossy/resources/server'
1
+ import { GetResource, PatchResourceContent } from '@ossy/resources'
2
2
  import BookingCancellationEmail from './booking-cancellation.email.jsx'
3
3
 
4
4
  export const metadata = { id: '@ossy/booking/tasks/decline' }
5
5
 
6
- export async function run ({ payload, req, log, integrations }) {
6
+ async function loadBooking (sdk, bookingId) {
7
+ try {
8
+ const booking = await sdk.invoke(GetResource, { resourceId: bookingId })
9
+ if (!booking?.id) throw Object.assign(new Error('Booking not found'), { status: 404 })
10
+ return booking
11
+ } catch (err) {
12
+ if (err?.status === 404) throw Object.assign(new Error('Booking not found'), { status: 404 })
13
+ throw err
14
+ }
15
+ }
16
+
17
+ export async function run ({ payload, req, log, integrations, sdk }) {
7
18
  const bookingId = payload?.bookingId ?? req?.params?.bookingId
8
19
  const workspaceId = payload?.workspaceId ?? req?.workspaceId
9
20
  const reason = payload?.reason ?? null
10
21
 
11
22
  if (!bookingId) throw Object.assign(new Error('bookingId is required'), { status: 400 })
23
+ if (!sdk?.invoke) throw Object.assign(new Error('sdk is required'), { status: 500 })
12
24
 
13
25
  log?.info(`[booking/tasks/decline] Declining booking ${bookingId}`)
14
26
 
15
- const booking = await viewResource(bookingId)
16
- if (!booking?.id) throw Object.assign(new Error('Booking not found'), { status: 404 })
27
+ const booking = await loadBooking(sdk, bookingId)
17
28
 
18
29
  if (booking.belongsTo !== workspaceId) {
19
30
  throw Object.assign(new Error('You do not have permission to decline this booking'), { status: 403 })
@@ -27,15 +38,10 @@ export async function run ({ payload, req, log, integrations }) {
27
38
  throw Object.assign(new Error('Use cancel-booking to cancel an already confirmed booking'), { status: 409 })
28
39
  }
29
40
 
30
- await mutateResource(
31
- bookingId,
32
- ResourcesEvents.Patched({
33
- createdBy: req?.userId ?? 'system',
34
- // Required for BookingListProjection.scopeFromEvent (live projection updates).
35
- belongsTo: booking.belongsTo,
36
- content: { ...booking.content, status: 'cancelled', declineReason: reason ?? '' },
37
- }),
38
- )
41
+ await sdk.invoke(PatchResourceContent, {
42
+ resourceId: bookingId,
43
+ content: { status: 'cancelled', declineReason: reason ?? '' },
44
+ })
39
45
 
40
46
  log?.info(`[booking/tasks/decline] Booking ${bookingId} declined`)
41
47
 
@@ -1,4 +1,4 @@
1
- import { ResourcesEvents, mutateResource } from '@ossy/resources/server'
1
+ import { ResourceStream, ResourcesEvents } from '@ossy/resources/server'
2
2
  import { BookingSchema } from './schema-ids.js'
3
3
  import { getBookingResources } from './booking-resources.js'
4
4
 
@@ -15,9 +15,11 @@ export async function run ({ payload, req, log }) {
15
15
  throw Object.assign(new Error('serviceId is required'), { status: 400 })
16
16
  }
17
17
 
18
+ const actor = ResourceStream.actor({ req, payload })
18
19
  const existing = await getBookingResources({
19
20
  schemaId: BookingSchema.service,
20
21
  belongsTo: workspaceId,
22
+ user: actor.kind === 'system' ? actor : actor.user,
21
23
  })
22
24
 
23
25
  const resource = existing.find(r => r.id === serviceId)
@@ -27,11 +29,12 @@ export async function run ({ payload, req, log }) {
27
29
 
28
30
  log?.info(`[booking/tasks/delete-service] Deleting service ${serviceId}`)
29
31
 
30
- await mutateResource(
32
+ await ResourceStream.mutate(
31
33
  serviceId,
32
34
  ResourcesEvents.Deleted({
33
35
  createdBy: req?.userId ?? 'system',
34
36
  }),
37
+ actor,
35
38
  )
36
39
 
37
40
  return { id: serviceId, deleted: true }
@@ -1,3 +1,4 @@
1
+ import { ResourceStream } from '@ossy/resources/server'
1
2
  import { getBookingResources } from './booking-resources.js'
2
3
  import { BookingSchema } from './schema-ids.js'
3
4
 
@@ -12,9 +13,11 @@ export async function run({ payload, req, log }) {
12
13
 
13
14
  log?.info(`[booking/tasks/get-availability] Loading availability for workspace ${workspaceId}`)
14
15
 
16
+ const actor = ResourceStream.actor({ req, payload })
15
17
  const resources = await getBookingResources({
16
18
  schemaId: BookingSchema.availability,
17
19
  belongsTo: workspaceId,
20
+ user: actor.kind === 'system' ? actor : actor.user,
18
21
  })
19
22
 
20
23
  if (!resources.length) {
@@ -1,3 +1,4 @@
1
+ import { ResourceStream } from '@ossy/resources/server'
1
2
  import { getAvailableSlots } from './availability-engine.js'
2
3
  import { getBookingResources } from './booking-resources.js'
3
4
  import { BookingSchema } from './schema-ids.js'
@@ -24,6 +25,7 @@ export async function run ({ payload, log }) {
24
25
  const serviceResources = await getBookingResources({
25
26
  schemaId: BookingSchema.service,
26
27
  belongsTo: workspaceId,
28
+ user: ResourceStream.system('booking-public'),
27
29
  })
28
30
  const service = serviceResources.find(r => r.id === serviceId)
29
31
  if (service?.content?.duration) {
@@ -34,6 +36,7 @@ export async function run ({ payload, log }) {
34
36
  const availabilityResources = await getBookingResources({
35
37
  schemaId: BookingSchema.availability,
36
38
  belongsTo: workspaceId,
39
+ user: ResourceStream.system('booking-public'),
37
40
  })
38
41
 
39
42
  if (!availabilityResources.length) {
@@ -73,6 +76,7 @@ export async function run ({ payload, log }) {
73
76
  const allBookingResources = await getBookingResources({
74
77
  schemaId: BookingSchema.booking,
75
78
  belongsTo: workspaceId,
79
+ user: ResourceStream.system('booking-public'),
76
80
  })
77
81
 
78
82
  const confirmedBookings = allBookingResources
@@ -1,3 +1,4 @@
1
+ import { ResourceStream } from '@ossy/resources/server'
1
2
  import { getBookingResources } from './booking-resources.js'
2
3
  import { BookingSchema } from './schema-ids.js'
3
4
  import { resolveWorkspaceContact, resolveWorkspaceId } from './resolve-workspace-contact.js'
@@ -16,6 +17,7 @@ export async function run ({ payload, req, log }) {
16
17
  const resources = await getBookingResources({
17
18
  schemaId: BookingSchema.service,
18
19
  belongsTo: workspaceId,
20
+ user: ResourceStream.system('booking-public'),
19
21
  })
20
22
 
21
23
  const includeInactive = payload?.includeInactive === true
@@ -1,4 +1,5 @@
1
1
  import { getProjection } from '@ossy/event-store'
2
+ import { ResourceStream } from '@ossy/resources/server'
2
3
  import { getBookingResources } from './booking-resources.js'
3
4
  import { BookingListProjection } from './booking-list.aggregate.js'
4
5
  import { BookingSchema } from './schema-ids.js'
@@ -10,8 +11,12 @@ export async function run({ payload, req, log }) {
10
11
  const workspaceId = req?.workspaceId
11
12
  const status = payload?.status ?? null
12
13
 
14
+ const actor = ResourceStream.actor({ req, payload })
15
+ const member = actor.kind === 'system' || actor.user?.workspaces?.includes(workspaceId)
13
16
  log?.info(`[booking/tasks/list] Loading bookings for workspace ${workspaceId}`, { status })
14
17
 
18
+ if (!member) return []
19
+
15
20
  let bookings = await loadFromProjection(workspaceId)
16
21
 
17
22
  if (bookings == null) {
@@ -19,6 +24,7 @@ export async function run({ payload, req, log }) {
19
24
  const resources = await getBookingResources({
20
25
  schemaId: BookingSchema.booking,
21
26
  belongsTo: workspaceId,
27
+ user: actor.kind === 'system' ? actor : actor.user,
22
28
  })
23
29
  bookings = resources.map(r => ({
24
30
  id: r.id,
@@ -24,9 +24,18 @@ export default {
24
24
  steps: [
25
25
  ...providerOnboard.steps,
26
26
  { action: OpenServices },
27
- { result: { selector: '[data-services-status]', timeout: 15000 } },
27
+ // Wait until the list finished loading — clicking Add during `loading` can
28
+ // lose the open-form state when the first GetServices resolve remounts.
29
+ {
30
+ result: {
31
+ selector: '[data-services-status="empty"], [data-services-status="populated"]',
32
+ timeout: 20000,
33
+ },
34
+ },
35
+ { press: 'Escape' },
28
36
  { result: { action: OpenCreateService, timeout: 10000 } },
29
37
  { action: OpenCreateService },
38
+ { result: { selector: '[data-services-form="open"]', timeout: 10000 } },
30
39
  { result: { action: CreateService, timeout: 15000 } },
31
40
  { form: ServiceForm },
32
41
  { action: CreateService },
@@ -250,7 +250,18 @@ export default function PublicBookingPage ({ providerSlug }) {
250
250
  from,
251
251
  to,
252
252
  })
253
- .then(data => { setSlots(data); setLoadingSlots(false) })
253
+ .then(data => {
254
+ setSlots(data)
255
+ setLoadingSlots(false)
256
+ // Auto-advance the calendar to the first month that has available slots
257
+ // so the date picker is immediately usable (avoids end-of-month flakes
258
+ // where the current month has no future slots but next month does).
259
+ if (Array.isArray(data) && data.length > 0) {
260
+ const first = new Date(data[0].startAt)
261
+ setCalYear(first.getFullYear())
262
+ setCalMonth(first.getMonth())
263
+ }
264
+ })
254
265
  .catch(() => { setSlotsError(t('publicBooking.slotsError')); setLoadingSlots(false) })
255
266
  }, [slug, selectedService, step, sdk, t])
256
267
 
@@ -1,5 +1,5 @@
1
1
  import { nanoid } from 'nanoid'
2
- import { ResourcesEvents, commitResource, mutateResource } from '@ossy/resources/server'
2
+ import { ResourceStream, ResourcesEvents } from '@ossy/resources/server'
3
3
  import { BookingSchema } from './schema-ids.js'
4
4
  import { getBookingResources } from './booking-resources.js'
5
5
  import { availability } from './locations.js'
@@ -30,9 +30,11 @@ export async function run ({ payload, req, log }) {
30
30
  timezone: timezone ?? 'Europe/Stockholm',
31
31
  }
32
32
 
33
+ const actor = ResourceStream.actor({ req, payload })
33
34
  const existing = await getBookingResources({
34
35
  schemaId: BookingSchema.availability,
35
36
  belongsTo: workspaceId,
37
+ user: actor.kind === 'system' ? actor : actor.user,
36
38
  })
37
39
 
38
40
  const configResource = existing.find(r => Array.isArray(r.content?.weeklyWindows))
@@ -40,12 +42,13 @@ export async function run ({ payload, req, log }) {
40
42
  if (configResource) {
41
43
  log?.info(`[booking/tasks/save-availability] Updating existing resource ${configResource.id}`)
42
44
 
43
- await mutateResource(
45
+ await ResourceStream.mutate(
44
46
  configResource.id,
45
47
  ResourcesEvents.Patched({
46
48
  createdBy: req?.userId ?? 'system',
47
49
  content,
48
50
  }),
51
+ actor,
49
52
  )
50
53
 
51
54
  return { id: configResource.id, content }
@@ -64,7 +67,7 @@ export async function run ({ payload, req, log }) {
64
67
  content,
65
68
  })
66
69
 
67
- await commitResource(event)
70
+ await ResourceStream.commit(event, actor)
68
71
 
69
72
  log?.info(`[booking/tasks/save-availability] Resource ${resourceId} created`)
70
73
 
@@ -1,3 +1,4 @@
1
+ import { ResourceStream } from '@ossy/resources/server'
1
2
  import { getBookingResources } from './booking-resources.js'
2
3
  import { BookingSchema } from './schema-ids.js'
3
4
  import BookingReminderEmail from './booking-reminder.email.jsx'
@@ -19,6 +20,7 @@ export async function run({ sdk, log, integrations }) {
19
20
 
20
21
  const allBookings = await getBookingResources({
21
22
  schemaId: BookingSchema.booking,
23
+ user: ResourceStream.system('booking-reminder'),
22
24
  })
23
25
 
24
26
  const upcoming = allBookings.filter(b => {
@@ -115,6 +115,7 @@ export default function ServicesPage () {
115
115
 
116
116
  return (
117
117
  <Page
118
+ data-services-form={formOpen ? 'open' : 'closed'}
118
119
  header={(
119
120
  <ContentHeader
120
121
  inset="none"
@@ -1,4 +1,4 @@
1
- import { ResourcesEvents, mutateResource } from '@ossy/resources/server'
1
+ import { ResourceStream, ResourcesEvents } from '@ossy/resources/server'
2
2
  import { BookingSchema } from './schema-ids.js'
3
3
  import { getBookingResources } from './booking-resources.js'
4
4
 
@@ -15,9 +15,11 @@ export async function run ({ payload, req, log }) {
15
15
  throw Object.assign(new Error('serviceId is required'), { status: 400 })
16
16
  }
17
17
 
18
+ const actor = ResourceStream.actor({ req, payload })
18
19
  const existing = await getBookingResources({
19
20
  schemaId: BookingSchema.service,
20
21
  belongsTo: workspaceId,
22
+ user: actor.kind === 'system' ? actor : actor.user,
21
23
  })
22
24
 
23
25
  const resource = existing.find(r => r.id === serviceId)
@@ -37,12 +39,13 @@ export async function run ({ payload, req, log }) {
37
39
 
38
40
  log?.info(`[booking/tasks/update-service] Updating service ${serviceId}`)
39
41
 
40
- await mutateResource(
42
+ await ResourceStream.mutate(
41
43
  serviceId,
42
44
  ResourcesEvents.Patched({
43
45
  createdBy: req?.userId ?? 'system',
44
46
  content,
45
47
  }),
48
+ actor,
46
49
  )
47
50
 
48
51
  return { id: serviceId, ...content }