@flowselections/floriday-verkoop-module 1.0.147 → 1.0.149

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.
@@ -87,9 +87,15 @@ export declare const listPickupLocationsCO: import("@tanstack/start-client-core"
87
87
  userId: string;
88
88
  claims: import("@supabase/auth-js").User;
89
89
  }, undefined, undefined, undefined>], undefined, Promise<{
90
+ source: "eigen";
91
+ items: any;
92
+ } | {
93
+ source: "floriday";
90
94
  items: {
91
95
  id: string;
92
96
  name: any;
97
+ isDefault: boolean;
98
+ source: "floriday";
93
99
  }[];
94
100
  }>>;
95
101
  export declare const listCarriersForCreateOrder: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
@@ -1 +1 @@
1
- {"version":3,"file":"create-order.functions.d.ts","sourceRoot":"","sources":["../../src/lib/create-order.functions.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,2BAA2B;;;;;;YAwBpB,MAAM;sBACc,MAAM,GAAG,IAAI;yBACG,MAAM,GAAG,IAAI;cACnC,MAAM,GAAG,IAAI;eACX,MAAM,GAAG,IAAI;wBACK,MAAM,GAAG,IAAI;gBACvC,MAAM;;;GAkB9B,CAAC;AAIL,eAAO,MAAM,2BAA2B;;;;0CAElB,OAAO;;;;GAoDzB,CAAC;AAWL,eAAO,MAAM,0BAA0B;;;;;;;;YA+D7B,MAAM;iBACD,MAAM;sBACD,MAAM,GAAG,IAAI;cACrB,MAAM;oBACA,MAAM,GAAG,IAAI;0BACP,MAAM,GAAG,IAAI;0BACb,MAAM,GAAG,IAAI;yBACd,MAAM,GAAG,IAAI;wBACd,MAAM;wBACN,MAAM;yBACL,MAAM;kBACb,OAAO;gBACT,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS;;GA6TpD,CAAC;AAGL,eAAO,MAAM,kCAAkC;;;;0CAEzB,OAAO;;;;;;;;;;;;;;;;;;;;;;G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B,CAAC;AAKL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;;GAc7B,CAAC;AAQL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;GAoG7B,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;8CAER,OAAO;;;;GAyB7B,CAAC;AAkDL,eAAO,MAAM,oBAAoB;;;;8CAEP,OAAO;;;aA2JG,MAAM;iBACQ,MAAM,GAAG,IAAI;kBACX,MAAM;;YAEnB,MAAM,GAAG,IAAI;;;;;;YA8B7B,MAAM;mBACS,MAAM,GAAG,IAAI;qBACT,MAAM;;cAErB,MAAM,GAAG,IAAI;;;;;;;;GAUpC,CAAC;AAIL,eAAO,MAAM,gBAAgB;;;;8CAEH,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuT7B,CAAC;AAKL,eAAO,MAAM,kBAAkB;;;;8CAEL,OAAO;;;;;;;;WAUM,MAAM;YAAU,MAAM,GAAG,IAAI;WAmBhE,CAAC;AAOL,eAAO,MAAM,2BAA2B;;;;8CAEd,OAAO;;;;gBAIgC,MAAM,EAAE;GAoCrE,CAAC"}
@@ -573,10 +573,29 @@ export const getLastPickupLocationCO = createServerFn({ method: "POST" })
573
573
  const v = rows?.[0]?.custom_fields?.pickup_location;
574
574
  return { pickupLocationId: typeof v === "string" && v.trim() ? v.trim() : null };
575
575
  });
576
- // ─── Afhaallocaties (eigen tuinen) — Floriday warehouses ────────────────────
576
+ // ─── Afhaallocaties (eigen tuinen) — één bron, volgens de Floriday-koppeling ─
577
+ // Actieve koppeling → alleen Floriday-warehouses; geen koppeling → alleen de
578
+ // eigen locaties (verkoop_pickup_locations, Instellingen). Zie pickup-locations.server.ts.
577
579
  export const listPickupLocationsCO = createServerFn({ method: "GET" })
578
580
  .middleware([requireSupabaseAuth])
579
581
  .handler(async ({ context }) => {
582
+ const { resolvePickupSource } = await import("./pickup-locations.server.js");
583
+ const source = await resolvePickupSource(context.supabase);
584
+ if (source === "eigen") {
585
+ // Ontbrekende tabel (schema nog niet bijgewerkt) = nog geen eigen locaties.
586
+ const ownRes = await context.supabase.from("verkoop_pickup_locations")
587
+ .select("id, name, is_default")
588
+ .eq("is_active", true);
589
+ const items = (Array.isArray(ownRes?.data) ? ownRes.data : [])
590
+ .map((r) => ({
591
+ id: r.id,
592
+ name: String(r.name ?? "").trim() || "(naamloos)",
593
+ isDefault: r.is_default === true,
594
+ source: "eigen",
595
+ }))
596
+ .sort((a, b) => a.name.localeCompare(b.name, "nl"));
597
+ return { source, items };
598
+ }
580
599
  const { data } = await context.supabase
581
600
  .from("floriday_warehouses_cache")
582
601
  .select("floriday_id, name, data")
@@ -594,10 +613,10 @@ export const listPickupLocationsCO = createServerFn({ method: "GET" })
594
613
  const label = nameRaw.length > 0
595
614
  ? nameRaw
596
615
  : [addr, city].filter(Boolean).join(", ") || "(naamloos)";
597
- return { id: r.floriday_id, name: label };
616
+ return { id: r.floriday_id, name: label, isDefault: false, source: "floriday" };
598
617
  })
599
618
  .sort((a, b) => a.name.localeCompare(b.name, "nl"));
600
- return { items };
619
+ return { source, items };
601
620
  });
602
621
  // ─── Vervoerders ────────────────────────────────────────────────────────────
603
622
  export const listCarriersForCreateOrder = createServerFn({ method: "GET" })
@@ -8,7 +8,7 @@ export interface OrderAddress {
8
8
  }
9
9
  /**
10
10
  * Resolvt afleveradres (customer_delivery_locations) en ophaaladres
11
- * (floriday_warehouses_cache) voor een order. `orderId` mag een lokale
11
+ * (floriday_warehouses_cache, anders verkoop_pickup_locations) voor een order. `orderId` mag een lokale
12
12
  * orders.id (uuid) of een Floriday sales-order-id zijn.
13
13
  */
14
14
  export declare const getOrderAddresses: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
@@ -1 +1 @@
1
- {"version":3,"file":"order-addresses.functions.d.ts","sourceRoot":"","sources":["../../src/lib/order-addresses.functions.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AASD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;8CAEJ,OAAO;;;cAmBjB,MAAM,GAAG,IAAI;cACb,YAAY,GAAG,IAAI;YACrB,YAAY,GAAG,IAAI;GAyD7B,CAAC"}
1
+ {"version":3,"file":"order-addresses.functions.d.ts","sourceRoot":"","sources":["../../src/lib/order-addresses.functions.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AASD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;8CAEJ,OAAO;;;cAmBjB,MAAM,GAAG,IAAI;cACb,YAAY,GAAG,IAAI;YACrB,YAAY,GAAG,IAAI;GA2E7B,CAAC"}
@@ -11,7 +11,7 @@ function s(v) {
11
11
  }
12
12
  /**
13
13
  * Resolvt afleveradres (customer_delivery_locations) en ophaaladres
14
- * (floriday_warehouses_cache) voor een order. `orderId` mag een lokale
14
+ * (floriday_warehouses_cache, anders verkoop_pickup_locations) voor een order. `orderId` mag een lokale
15
15
  * orders.id (uuid) of een Floriday sales-order-id zijn.
16
16
  */
17
17
  export const getOrderAddresses = createServerFn({ method: "GET" })
@@ -62,6 +62,24 @@ export const getOrderAddresses = createServerFn({ method: "GET" })
62
62
  gln: s(loc.gln ?? loc.glnCode),
63
63
  };
64
64
  }
65
+ // Geen Floriday-warehouse: eigen afhaallocatie (ook gearchiveerde, voor oude orders).
66
+ if (!pickup && /^[0-9a-f-]{36}$/i.test(pickupRef)) {
67
+ const own = await supabase.from("verkoop_pickup_locations")
68
+ .select("name, address_line, postal_code, city, country, gln")
69
+ .eq("id", pickupRef)
70
+ .maybeSingle();
71
+ const o = own?.data;
72
+ if (o) {
73
+ pickup = {
74
+ name: s(o.name),
75
+ line: s(o.address_line),
76
+ postalCode: s(o.postal_code),
77
+ city: s(o.city),
78
+ country: s(o.country),
79
+ gln: s(o.gln),
80
+ };
81
+ }
82
+ }
65
83
  }
66
84
  // Koper-GLN: gekoppelde klant, anders de Floriday-koper van de order.
67
85
  let buyerGln = null;
@@ -0,0 +1,44 @@
1
+ export interface OwnPickupLocation {
2
+ id: string;
3
+ name: string;
4
+ addressLine: string | null;
5
+ postalCode: string | null;
6
+ city: string | null;
7
+ country: string | null;
8
+ gln: string | null;
9
+ isDefault: boolean;
10
+ }
11
+ export declare const listOwnPickupLocations: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
12
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
13
+ userId: string;
14
+ claims: import("@supabase/auth-js").User;
15
+ }, undefined, undefined, undefined>], undefined, Promise<{
16
+ items: OwnPickupLocation[];
17
+ source: "floriday" | "eigen" | null;
18
+ }>>;
19
+ export declare const saveOwnPickupLocation: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
20
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
21
+ userId: string;
22
+ claims: import("@supabase/auth-js").User;
23
+ }, undefined, undefined, undefined>], (input: unknown) => {
24
+ name: string;
25
+ addressLine: string | null;
26
+ postalCode: string | null;
27
+ city: string | null;
28
+ country: string | null;
29
+ gln: string | null;
30
+ isDefault: boolean;
31
+ id?: string | null | undefined;
32
+ }, Promise<{
33
+ id: string;
34
+ }>>;
35
+ export declare const archiveOwnPickupLocation: import("@tanstack/start-client-core").OptionalFetcher<readonly [import("@tanstack/start-client-core").FunctionMiddlewareAfterServer<{}, unknown, undefined, {
36
+ supabase: import("../integrations/supabase/auth-middleware.js").AuthedSupabaseClient;
37
+ userId: string;
38
+ claims: import("@supabase/auth-js").User;
39
+ }, undefined, undefined, undefined>], (input: unknown) => {
40
+ id: string;
41
+ }, Promise<{
42
+ ok: true;
43
+ }>>;
44
+ //# sourceMappingURL=pickup-locations.functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pickup-locations.functions.d.ts","sourceRoot":"","sources":["../../src/lib/pickup-locations.functions.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACpB;AA2BD,eAAO,MAAM,sBAAsB;;;;;WAEc,iBAAiB,EAAE;YAAU,UAAU,GAAG,OAAO,GAAG,IAAI;GAoBrG,CAAC;AAEL,eAAO,MAAM,qBAAqB;;;;8CAER,OAAO;;;;;;;;;;;GA+B7B,CAAC;AAEL,eAAO,MAAM,wBAAwB;;;;8CAEX,OAAO;;;;GAS7B,CAAC"}
@@ -0,0 +1,104 @@
1
+ // Eigen afhaallocaties (tuinen) voor accounts zonder Floriday-koppeling.
2
+ // "Nieuwe bestelling" gebruikt ze alleen zonder actieve Floriday-koppeling
3
+ // (listPickupLocationsCO, pickup-locations.server.ts).
4
+ // Verwijderen zet alleen is_active uit, zodat bestaande orders hun adres houden.
5
+ import { createServerFn } from "@tanstack/react-start";
6
+ import { z } from "zod";
7
+ import { requireSupabaseAuth } from "../integrations/supabase/auth-middleware.js";
8
+ const opt = z
9
+ .string()
10
+ .max(200)
11
+ .nullable()
12
+ .optional()
13
+ .transform((v) => (v && v.trim() ? v.trim() : null));
14
+ const saveSchema = z.object({
15
+ id: z.string().uuid().nullable().optional(),
16
+ name: z.string().trim().min(1, "Naam is verplicht").max(120),
17
+ addressLine: opt,
18
+ postalCode: opt,
19
+ city: opt,
20
+ country: opt,
21
+ gln: z
22
+ .string()
23
+ .nullable()
24
+ .optional()
25
+ .transform((v) => (v && v.trim() ? v.trim() : null))
26
+ .refine((v) => v === null || /^\d{13}$/.test(v), "GLN bestaat uit 13 cijfers"),
27
+ isDefault: z.boolean(),
28
+ });
29
+ const table = (supabase) => supabase.from("verkoop_pickup_locations");
30
+ export const listOwnPickupLocations = createServerFn({ method: "GET" })
31
+ .middleware([requireSupabaseAuth])
32
+ .handler(async ({ context }) => {
33
+ const { resolvePickupSource } = await import("./pickup-locations.server.js");
34
+ // Alleen voor de melding op de kaart; een mislukte controle verbergt die melding.
35
+ const source = await resolvePickupSource(context.supabase).catch(() => null);
36
+ const { data, error } = await table(context.supabase)
37
+ .select("id, name, address_line, postal_code, city, country, gln, is_default")
38
+ .eq("is_active", true)
39
+ .order("name");
40
+ if (error)
41
+ throw new Error(`Afhaallocaties konden niet worden geladen: ${error.message}`);
42
+ const items = (data ?? []).map((r) => ({
43
+ id: r.id,
44
+ name: r.name,
45
+ addressLine: r.address_line ?? null,
46
+ postalCode: r.postal_code ?? null,
47
+ city: r.city ?? null,
48
+ country: r.country ?? null,
49
+ gln: r.gln ?? null,
50
+ isDefault: r.is_default === true,
51
+ }));
52
+ return { items, source };
53
+ });
54
+ export const saveOwnPickupLocation = createServerFn({ method: "POST" })
55
+ .middleware([requireSupabaseAuth])
56
+ .inputValidator((input) => saveSchema.parse(input))
57
+ .handler(async ({ data, context }) => {
58
+ const supabase = context.supabase;
59
+ const row = {
60
+ name: data.name,
61
+ address_line: data.addressLine,
62
+ postal_code: data.postalCode,
63
+ city: data.city,
64
+ country: data.country,
65
+ gln: data.gln,
66
+ is_default: data.isDefault,
67
+ updated_at: new Date().toISOString(),
68
+ };
69
+ // Eén standaard: eerst de huidige standaard uitzetten (unieke index bewaakt dit).
70
+ if (data.isDefault) {
71
+ let q = table(supabase).update({ is_default: false }).eq("is_default", true);
72
+ if (data.id)
73
+ q = q.neq("id", data.id);
74
+ const { error } = await q;
75
+ if (error)
76
+ throw new Error(error.message);
77
+ }
78
+ if (data.id) {
79
+ const { data: rows, error } = await table(supabase).update(row).eq("id", data.id).select("id");
80
+ if (error)
81
+ throw new Error(error.message);
82
+ if (!rows || rows.length === 0)
83
+ throw new Error("Afhaallocatie niet gevonden");
84
+ return { id: data.id };
85
+ }
86
+ const { data: created, error } = await table(supabase).insert(row).select("id").maybeSingle();
87
+ if (error)
88
+ throw new Error(error.message);
89
+ return { id: created?.id };
90
+ });
91
+ export const archiveOwnPickupLocation = createServerFn({ method: "POST" })
92
+ .middleware([requireSupabaseAuth])
93
+ .inputValidator((input) => z.object({ id: z.string().uuid() }).parse(input))
94
+ .handler(async ({ data, context }) => {
95
+ const { data: rows, error } = await table(context.supabase)
96
+ .update({ is_active: false, is_default: false, updated_at: new Date().toISOString() })
97
+ .eq("id", data.id)
98
+ .select("id");
99
+ if (error)
100
+ throw new Error(error.message);
101
+ if (!rows || rows.length === 0)
102
+ throw new Error("Afhaallocatie niet gevonden");
103
+ return { ok: true };
104
+ });
@@ -0,0 +1,6 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ export type PickupSource = "floriday" | "eigen";
3
+ /** true = actieve Floriday-koppeling. Ontbreekt de functie (geen Authenticatie-module), dan geen koppeling. */
4
+ export declare function hasActiveFloridayConnection(supabase: SupabaseClient): Promise<boolean>;
5
+ export declare function resolvePickupSource(supabase: SupabaseClient): Promise<PickupSource>;
6
+ //# sourceMappingURL=pickup-locations.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pickup-locations.server.d.ts","sourceRoot":"","sources":["../../src/lib/pickup-locations.server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC;AAEhD,+GAA+G;AAC/G,wBAAsB,2BAA2B,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAU5F;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAEzF"}
@@ -0,0 +1,16 @@
1
+ /** true = actieve Floriday-koppeling. Ontbreekt de functie (geen Authenticatie-module), dan geen koppeling. */
2
+ export async function hasActiveFloridayConnection(supabase) {
3
+ const { data, error } = await supabase.rpc("get_active_floriday_connection_public");
4
+ if (error) {
5
+ const missing = error.code === "42883" || error.code === "PGRST202";
6
+ if (missing)
7
+ return false;
8
+ // Onbekende stand: niet gokken, anders komen orders op de verkeerde locatie.
9
+ throw new Error(`Floriday-koppeling kon niet worden gecontroleerd: ${error.message}`);
10
+ }
11
+ const rows = Array.isArray(data) ? data : data ? [data] : [];
12
+ return rows.some((r) => typeof r?.id === "string" && r.id.length > 0);
13
+ }
14
+ export async function resolvePickupSource(supabase) {
15
+ return (await hasActiveFloridayConnection(supabase)) ? "floriday" : "eigen";
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowselections/floriday-verkoop-module",
3
- "version": "1.0.147",
3
+ "version": "1.0.149",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@flowselections/core": "1.0.35",
39
+ "@flowselections/layout-maker": "^1.13.2",
39
40
  "@tanstack/react-query": "^5.0.0",
40
41
  "@tanstack/react-router": "^1.0.0",
41
42
  "@tanstack/react-start": "^1.0.0",
@@ -45,7 +46,6 @@
45
46
  "sonner": "^2.0.0"
46
47
  },
47
48
  "dependencies": {
48
- "@flowselections/layout-maker": "1.13.2",
49
49
  "@supabase/supabase-js": "^2.110.7",
50
50
  "date-fns": "^4.3.0",
51
51
  "zod": "^4.4.3"
@@ -54,6 +54,7 @@
54
54
  "@cloudflare/vite-plugin": "^1.25.5",
55
55
  "@eslint/js": "^9.32.0",
56
56
  "@flowselections/core": "1.0.35",
57
+ "@flowselections/layout-maker": "1.13.2",
57
58
  "@lovable.dev/vite-tanstack-config": "2.26.5",
58
59
  "@rsbuild/core": "^1.0.0",
59
60
  "@tailwindcss/vite": "^4.2.1",
@@ -2569,6 +2569,30 @@ DO $$ BEGIN
2569
2569
  END IF;
2570
2570
  END $$;
2571
2571
 
2572
+ -- Eigen afhaallocaties (accounts zonder Floriday-koppeling); id staat in orders.custom_fields.pickup_location.
2573
+ CREATE TABLE IF NOT EXISTS public.verkoop_pickup_locations (
2574
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
2575
+ name text NOT NULL,
2576
+ address_line text,
2577
+ postal_code text,
2578
+ city text,
2579
+ country text,
2580
+ gln text,
2581
+ is_default boolean NOT NULL DEFAULT false,
2582
+ is_active boolean NOT NULL DEFAULT true,
2583
+ created_at timestamptz NOT NULL DEFAULT now(),
2584
+ updated_at timestamptz NOT NULL DEFAULT now()
2585
+ );
2586
+ CREATE UNIQUE INDEX IF NOT EXISTS verkoop_pickup_locations_one_default ON public.verkoop_pickup_locations (is_default) WHERE is_default AND is_active;
2587
+ GRANT SELECT, INSERT, UPDATE ON public.verkoop_pickup_locations TO authenticated;
2588
+ GRANT ALL ON public.verkoop_pickup_locations TO service_role;
2589
+ ALTER TABLE public.verkoop_pickup_locations ENABLE ROW LEVEL SECURITY;
2590
+ DO $$ BEGIN
2591
+ IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE schemaname='public' AND tablename='verkoop_pickup_locations' AND policyname='Ingelogde gebruikers beheren afhaallocaties') THEN
2592
+ CREATE POLICY "Ingelogde gebruikers beheren afhaallocaties" ON public.verkoop_pickup_locations FOR ALL TO authenticated USING (true) WITH CHECK (true);
2593
+ END IF;
2594
+ END $$;
2595
+
2572
2596
  -- Eén afhandeling (fulfillment) naar de index. Schrijft alleen bij echte verschillen.
2573
2597
 
2574
2598