@sonatel-os/strapi-plugin-split 0.4.0 → 0.6.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 +15 -13
- package/dist/_chunks/{App-CLfoPnvq.js → App-CYAjChoJ.js} +52 -70
- package/dist/_chunks/{App-8QwzQSyg.mjs → App-CyHrReR9.mjs} +2 -20
- package/dist/_chunks/SettingsPage-BqEpGpCs.js +165 -0
- package/dist/_chunks/SettingsPage-By2SGFAk.mjs +165 -0
- package/dist/_chunks/{api-BCYZ56eI.mjs → format-CNjIwTKo.mjs} +55 -13
- package/dist/_chunks/{api-cwZGoKZx.js → format-Dr6t_23v.js} +46 -4
- package/dist/_chunks/{index-oyRhs5fN.js → index-Uv5-E0cg.js} +4 -3
- package/dist/_chunks/{index-PFbwTznf.mjs → index-oF7vL92A.mjs} +4 -3
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +158 -29
- package/dist/server/index.mjs +158 -29
- package/package.json +1 -1
- package/dist/_chunks/SettingsPage-B746YfAA.js +0 -101
- package/dist/_chunks/SettingsPage-CH92IYGk.mjs +0 -101
package/dist/server/index.mjs
CHANGED
|
@@ -24,7 +24,8 @@ const RBAC = Object.freeze({
|
|
|
24
24
|
PEOPLE_WRITE: "people.write",
|
|
25
25
|
SETTLEMENTS_READ: "settlements.read",
|
|
26
26
|
AUDIT_READ: "audit.read",
|
|
27
|
-
SETTINGS_READ: "settings.read"
|
|
27
|
+
SETTINGS_READ: "settings.read",
|
|
28
|
+
SETTINGS_WRITE: "settings.write"
|
|
28
29
|
});
|
|
29
30
|
const SPLIT_MODE = Object.freeze({ EQUAL: "equal", WEIGHTED: "weighted", FREE: "free" });
|
|
30
31
|
const ROLE = Object.freeze({ OWNER: "owner", MEMBER: "member" });
|
|
@@ -80,12 +81,20 @@ const ORDER_STATUS = Object.freeze({
|
|
|
80
81
|
const ORDER_MAX_ITEMS = 30;
|
|
81
82
|
const ORDER_MAX_QUANTITY = 99;
|
|
82
83
|
const ORDER_LIST_SIZE = 20;
|
|
84
|
+
const ORDER_NOTE_MAX = 80;
|
|
85
|
+
const ORDER_RECENT_MS = 24 * 60 * 60 * 1e3;
|
|
83
86
|
const DEFAULT_LIMITS = Object.freeze({
|
|
84
|
-
maxGroupsPerPerson:
|
|
85
|
-
maxMembersPerGroup:
|
|
87
|
+
maxGroupsPerPerson: 150,
|
|
88
|
+
maxMembersPerGroup: 150,
|
|
86
89
|
/** Largest single expense or settlement, in the currency's smallest unit. */
|
|
87
|
-
maxAmount:
|
|
90
|
+
maxAmount: 15e7
|
|
88
91
|
});
|
|
92
|
+
const LIMIT_CEILINGS = Object.freeze({
|
|
93
|
+
maxGroupsPerPerson: 1e3,
|
|
94
|
+
maxMembersPerGroup: 500,
|
|
95
|
+
maxAmount: 2e9
|
|
96
|
+
});
|
|
97
|
+
const LIMITS_STORE_KEY = "limits";
|
|
89
98
|
const DEFAULT_INVITE_PREFIX = "SPL";
|
|
90
99
|
const DEFAULT_COUNTRY_CODE = "";
|
|
91
100
|
const CODE_CHARSET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
@@ -142,6 +151,12 @@ const ACTIONS = [
|
|
|
142
151
|
category: PLUGIN_DISPLAY_NAME,
|
|
143
152
|
uid: RBAC.SETTINGS_READ,
|
|
144
153
|
displayName: "Read settings"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
section: "settings",
|
|
157
|
+
category: PLUGIN_DISPLAY_NAME,
|
|
158
|
+
uid: RBAC.SETTINGS_WRITE,
|
|
159
|
+
displayName: "Change the limits"
|
|
145
160
|
}
|
|
146
161
|
].map((a) => ({ ...a, pluginName: PLUGIN_ID }));
|
|
147
162
|
const UNIQUE_COLUMNS = [
|
|
@@ -843,7 +858,7 @@ const info = {
|
|
|
843
858
|
singularName: "order-line",
|
|
844
859
|
pluralName: "order-lines",
|
|
845
860
|
displayName: "Split Order Line",
|
|
846
|
-
description: "How many of one item one member takes."
|
|
861
|
+
description: "How many of one item one member takes, and what they ask about it."
|
|
847
862
|
};
|
|
848
863
|
const options = {
|
|
849
864
|
draftAndPublish: false
|
|
@@ -876,6 +891,10 @@ const attributes = {
|
|
|
876
891
|
type: "integer",
|
|
877
892
|
required: true,
|
|
878
893
|
min: 1
|
|
894
|
+
},
|
|
895
|
+
note: {
|
|
896
|
+
type: "string",
|
|
897
|
+
maxLength: 80
|
|
879
898
|
}
|
|
880
899
|
};
|
|
881
900
|
const schema = {
|
|
@@ -1093,6 +1112,7 @@ const app = ({ strapi }) => {
|
|
|
1093
1112
|
ok(ctx, svc("format").settlement(settlement2, mine.me, viewer(ctx)));
|
|
1094
1113
|
}),
|
|
1095
1114
|
// ── Orders ───────────────────────────────────────────────────────────
|
|
1115
|
+
currentOrders: handle(strapi, async (ctx) => ok(ctx, await svc("order").current(viewer(ctx)))),
|
|
1096
1116
|
orders: handle(
|
|
1097
1117
|
strapi,
|
|
1098
1118
|
async (ctx) => ok(ctx, await svc("order").list(await seat(ctx), viewer(ctx)))
|
|
@@ -1234,13 +1254,17 @@ const view = ({ strapi }) => {
|
|
|
1234
1254
|
const debts = perGroup.flatMap((g) => g.debts).sort((a, b) => b.amount - a.amount);
|
|
1235
1255
|
const credits = perGroup.flatMap((g) => g.credits).sort((a, b) => b.amount - a.amount);
|
|
1236
1256
|
const sum = (list) => list.reduce((total, item) => total + item.amount, 0);
|
|
1237
|
-
const invitations = await
|
|
1257
|
+
const [invitations, orders] = await Promise.all([
|
|
1258
|
+
svc("member").invitations(viewer),
|
|
1259
|
+
svc("order").current(viewer)
|
|
1260
|
+
]);
|
|
1238
1261
|
return {
|
|
1239
1262
|
owe: sum(debts),
|
|
1240
1263
|
owed: sum(credits),
|
|
1241
1264
|
debts,
|
|
1242
1265
|
credits,
|
|
1243
1266
|
invitations: invitations.map((seat) => format2.invitation(seat)),
|
|
1267
|
+
orders,
|
|
1244
1268
|
groups: perGroup.map((g) => g.summary).sort((a, b) => new Date(b.lastActivityAt ?? 0) - new Date(a.lastActivityAt ?? 0))
|
|
1245
1269
|
};
|
|
1246
1270
|
},
|
|
@@ -1394,8 +1418,16 @@ const admin$1 = ({ strapi }) => {
|
|
|
1394
1418
|
countryCode: settings2.countryCode(),
|
|
1395
1419
|
people: settings2.people(),
|
|
1396
1420
|
methods: settings2.methods(),
|
|
1397
|
-
limits: settings2.limits()
|
|
1421
|
+
limits: await settings2.limits(),
|
|
1422
|
+
limitCeilings: LIMIT_CEILINGS
|
|
1398
1423
|
});
|
|
1424
|
+
}),
|
|
1425
|
+
setLimits: handle(strapi, async (ctx) => {
|
|
1426
|
+
const limits = await svc("settings").setLimits(body(ctx));
|
|
1427
|
+
strapi.log.info(
|
|
1428
|
+
`${LOG_PREFIX} limits set to ${JSON.stringify(limits)} by admin ${ctx.state.user?.id}`
|
|
1429
|
+
);
|
|
1430
|
+
ok(ctx, limits);
|
|
1399
1431
|
})
|
|
1400
1432
|
};
|
|
1401
1433
|
};
|
|
@@ -1479,6 +1511,7 @@ const contentApi = [
|
|
|
1479
1511
|
route$1("POST", "/groups/:group/settlements/:settlement/reject", "rejectSettlement"),
|
|
1480
1512
|
route$1("POST", "/groups/:group/settlements/:settlement/cancel", "cancelSettlement"),
|
|
1481
1513
|
// orders: priced items the members order from; closing one writes an expense
|
|
1514
|
+
route$1("GET", "/orders", "currentOrders"),
|
|
1482
1515
|
route$1("GET", "/groups/:group/orders", "orders"),
|
|
1483
1516
|
route$1("POST", "/groups/:group/orders", "createOrder"),
|
|
1484
1517
|
route$1("GET", "/groups/:group/orders/:order", "order"),
|
|
@@ -1511,14 +1544,23 @@ const admin = [
|
|
|
1511
1544
|
route("PUT", "/people/:id/active", "setPersonActive", RBAC.PEOPLE_WRITE),
|
|
1512
1545
|
route("GET", "/settlements", "settlements", RBAC.SETTLEMENTS_READ),
|
|
1513
1546
|
route("GET", "/events", "events", RBAC.AUDIT_READ),
|
|
1514
|
-
route("GET", "/settings", "settings", RBAC.SETTINGS_READ)
|
|
1547
|
+
route("GET", "/settings", "settings", RBAC.SETTINGS_READ),
|
|
1548
|
+
route("PUT", "/settings/limits", "setLimits", RBAC.SETTINGS_WRITE)
|
|
1515
1549
|
];
|
|
1516
1550
|
const routes = {
|
|
1517
1551
|
"content-api": { type: "content-api", routes: contentApi },
|
|
1518
1552
|
admin: { type: "admin", routes: admin }
|
|
1519
1553
|
};
|
|
1520
1554
|
const DEFAULT_PEOPLE = Object.freeze({ idHeader: "x-person-id", nameHeader: "x-person-name" });
|
|
1555
|
+
const LIMIT_KEYS = Object.keys(DEFAULT_LIMITS);
|
|
1556
|
+
const withinCeiling = (key, value) => Number.isInteger(value) && value > 0 && value <= LIMIT_CEILINGS[key];
|
|
1557
|
+
const usable = (limits) => Object.fromEntries(
|
|
1558
|
+
LIMIT_KEYS.filter((key) => withinCeiling(key, limits?.[key])).map((key) => [key, limits[key]])
|
|
1559
|
+
);
|
|
1521
1560
|
const settings = ({ strapi }) => ({
|
|
1561
|
+
store() {
|
|
1562
|
+
return strapi.store({ type: "plugin", name: PLUGIN_ID });
|
|
1563
|
+
},
|
|
1522
1564
|
/** @returns {Object} the full plugin config */
|
|
1523
1565
|
all() {
|
|
1524
1566
|
return strapi.config.get(`plugin::${PLUGIN_ID}`) ?? {};
|
|
@@ -1545,8 +1587,34 @@ const settings = ({ strapi }) => ({
|
|
|
1545
1587
|
Object.entries(methods).map(([name, m]) => [name, { instant: Boolean(m?.instant) }])
|
|
1546
1588
|
);
|
|
1547
1589
|
},
|
|
1548
|
-
limits
|
|
1590
|
+
/** The limits from the configuration file, before anything set in the back office. */
|
|
1591
|
+
configuredLimits() {
|
|
1549
1592
|
return { ...DEFAULT_LIMITS, ...this.all().limits ?? {} };
|
|
1593
|
+
},
|
|
1594
|
+
/**
|
|
1595
|
+
* The limits in force: what an administrator set, else the configuration file, else the defaults.
|
|
1596
|
+
* @returns {Promise<{ maxGroupsPerPerson: number, maxMembersPerGroup: number, maxAmount: number }>}
|
|
1597
|
+
*/
|
|
1598
|
+
async limits() {
|
|
1599
|
+
const saved = await this.store().get({ key: LIMITS_STORE_KEY });
|
|
1600
|
+
return { ...this.configuredLimits(), ...usable(saved) };
|
|
1601
|
+
},
|
|
1602
|
+
/**
|
|
1603
|
+
* Sets the limits from the back office. Every limit is given, each a whole number from 1 to its
|
|
1604
|
+
* ceiling. Lowering one never touches what already exists: it only refuses what comes next.
|
|
1605
|
+
* @param {Object} input
|
|
1606
|
+
* @returns {Promise<Object>} the limits now in force
|
|
1607
|
+
*/
|
|
1608
|
+
async setLimits(input) {
|
|
1609
|
+
const refused = LIMIT_KEYS.filter((key) => !withinCeiling(key, input?.[key]));
|
|
1610
|
+
if (refused.length > 0)
|
|
1611
|
+
throw badRequest(
|
|
1612
|
+
ERROR_CODES.VALIDATION,
|
|
1613
|
+
"Chaque limite est un entier entre 1 et son plafond.",
|
|
1614
|
+
{ fields: refused, ceilings: LIMIT_CEILINGS }
|
|
1615
|
+
);
|
|
1616
|
+
await this.store().set({ key: LIMITS_STORE_KEY, value: usable(input) });
|
|
1617
|
+
return this.limits();
|
|
1550
1618
|
}
|
|
1551
1619
|
});
|
|
1552
1620
|
const audit = ({ strapi }) => ({
|
|
@@ -1994,7 +2062,7 @@ const group = ({ strapi }) => {
|
|
|
1994
2062
|
async create(person2, input) {
|
|
1995
2063
|
const name = cleanName(input.name);
|
|
1996
2064
|
if (!name) throw badRequest(ERROR_CODES.VALIDATION, "Donne un nom au groupe.");
|
|
1997
|
-
const limits = svc("settings").limits();
|
|
2065
|
+
const limits = await svc("settings").limits();
|
|
1998
2066
|
const held = await members().count({ where: { person: person2.id, ...HELD } });
|
|
1999
2067
|
if (held >= limits.maxGroupsPerPerson)
|
|
2000
2068
|
throw unprocessable(
|
|
@@ -2071,7 +2139,7 @@ const group = ({ strapi }) => {
|
|
|
2071
2139
|
});
|
|
2072
2140
|
if (existing && !existing.joinedAt) await svc("member").take({ ...existing, group: group2 }, person2);
|
|
2073
2141
|
if (existing) return group2;
|
|
2074
|
-
const limits = svc("settings").limits();
|
|
2142
|
+
const limits = await svc("settings").limits();
|
|
2075
2143
|
const count = await members().count({ where: { group: group2.id, leftAt: { $null: true } } });
|
|
2076
2144
|
if (count >= limits.maxMembersPerGroup)
|
|
2077
2145
|
throw unprocessable(ERROR_CODES.MEMBER_LIMIT, "Ce groupe est complet.");
|
|
@@ -2179,7 +2247,7 @@ const member = ({ strapi }) => {
|
|
|
2179
2247
|
*/
|
|
2180
2248
|
async add({ group: group2, me }, raw) {
|
|
2181
2249
|
const input = this.parse(raw);
|
|
2182
|
-
const limits = svc("settings").limits();
|
|
2250
|
+
const limits = await svc("settings").limits();
|
|
2183
2251
|
const seats = await members().findMany({
|
|
2184
2252
|
where: { group: group2.id, leftAt: { $null: true } },
|
|
2185
2253
|
populate: { person: true }
|
|
@@ -2394,10 +2462,10 @@ const expense = ({ strapi }) => {
|
|
|
2394
2462
|
* @returns {{ label: string, category: string|null, amount: number, mode: string, spentAt: Date,
|
|
2395
2463
|
* paidBy: number, shares: Array<{ member: number, amount: number, weight: number }> }}
|
|
2396
2464
|
*/
|
|
2397
|
-
parse(input, active) {
|
|
2465
|
+
async parse(input, active) {
|
|
2398
2466
|
const label2 = String(input?.label ?? "").trim().slice(0, LABEL_MAX);
|
|
2399
2467
|
if (!label2) throw badRequest(ERROR_CODES.VALIDATION, "Dis ce que tu as payé.");
|
|
2400
|
-
const { maxAmount } = svc("settings").limits();
|
|
2468
|
+
const { maxAmount } = await svc("settings").limits();
|
|
2401
2469
|
const amount = input?.amount;
|
|
2402
2470
|
if (!Number.isInteger(amount) || amount <= 0 || amount > maxAmount)
|
|
2403
2471
|
throw badRequest(ERROR_CODES.VALIDATION, "Montant invalide.", { maxAmount });
|
|
@@ -2453,7 +2521,7 @@ const expense = ({ strapi }) => {
|
|
|
2453
2521
|
const earlier = await this.replayed(group2, clientRef);
|
|
2454
2522
|
if (earlier) return { expense: earlier, replayed: true };
|
|
2455
2523
|
const { active } = await svc("ledger").of(group2);
|
|
2456
|
-
const { shares: list, ...data } = this.parse(input, active);
|
|
2524
|
+
const { shares: list, ...data } = await this.parse(input, active);
|
|
2457
2525
|
try {
|
|
2458
2526
|
const created = await strapi.db.transaction(async () => {
|
|
2459
2527
|
await svc("group").lock(group2);
|
|
@@ -2496,7 +2564,7 @@ const expense = ({ strapi }) => {
|
|
|
2496
2564
|
const { group: group2, me } = seat;
|
|
2497
2565
|
const expense2 = await this.editable(seat, documentId);
|
|
2498
2566
|
const { active } = await svc("ledger").of(group2);
|
|
2499
|
-
const { shares: list, ...data } = this.parse(input, active);
|
|
2567
|
+
const { shares: list, ...data } = await this.parse(input, active);
|
|
2500
2568
|
await strapi.db.transaction(async () => {
|
|
2501
2569
|
await svc("group").lock(group2);
|
|
2502
2570
|
await expenses().update({ where: { id: expense2.id }, data });
|
|
@@ -2559,7 +2627,7 @@ const settlement = ({ strapi }) => {
|
|
|
2559
2627
|
* (`to`) when the caller pays, the one who paid (`from`) when the caller received.
|
|
2560
2628
|
*/
|
|
2561
2629
|
async parse({ group: group2, me }, input) {
|
|
2562
|
-
const { maxAmount } = svc("settings").limits();
|
|
2630
|
+
const { maxAmount } = await svc("settings").limits();
|
|
2563
2631
|
const amount = input?.amount;
|
|
2564
2632
|
if (!Number.isInteger(amount) || amount <= 0 || amount > maxAmount)
|
|
2565
2633
|
throw badRequest(ERROR_CODES.VALIDATION, "Montant invalide.", { maxAmount });
|
|
@@ -2771,8 +2839,10 @@ const orderTotals = ({ items, lines, deliveryFee = 0 }) => {
|
|
|
2771
2839
|
};
|
|
2772
2840
|
const LINE_POPULATE = { item: { select: ["id"] }, member: { select: ["id"] } };
|
|
2773
2841
|
const ORDER_POPULATE = { organizer: { select: ["id"] } };
|
|
2842
|
+
const CURRENT_POPULATE = { group: { select: ["id"] }, organizer: { populate: { person: true } } };
|
|
2774
2843
|
const iso = (date) => date ? new Date(date).toISOString() : null;
|
|
2775
|
-
const
|
|
2844
|
+
const tidy = (raw, max) => String(raw ?? "").trim().replace(/\s+/g, " ").slice(0, max);
|
|
2845
|
+
const label = (raw) => tidy(raw, LABEL_MAX);
|
|
2776
2846
|
const invalid = (message, details) => badRequest(ERROR_CODES.VALIDATION, message, details);
|
|
2777
2847
|
const expenseRefOf = (order2) => `order:${order2.documentId}`;
|
|
2778
2848
|
const order = ({ strapi }) => {
|
|
@@ -2794,10 +2864,10 @@ const order = ({ strapi }) => {
|
|
|
2794
2864
|
return date;
|
|
2795
2865
|
},
|
|
2796
2866
|
/** What the organiser sent, checked. */
|
|
2797
|
-
parse(input) {
|
|
2867
|
+
async parse(input) {
|
|
2798
2868
|
const title = label(input?.title);
|
|
2799
2869
|
if (!title) throw invalid("Donne un nom à la commande.");
|
|
2800
|
-
const { maxAmount } = svc("settings").limits();
|
|
2870
|
+
const { maxAmount } = await svc("settings").limits();
|
|
2801
2871
|
const list = Array.isArray(input?.items) ? input.items : [];
|
|
2802
2872
|
if (list.length === 0 || list.length > ORDER_MAX_ITEMS)
|
|
2803
2873
|
throw invalid(`Entre 1 et ${ORDER_MAX_ITEMS} articles.`, { max: ORDER_MAX_ITEMS });
|
|
@@ -2812,7 +2882,7 @@ const order = ({ strapi }) => {
|
|
|
2812
2882
|
* @param {{ title: string, closesAt?: string, items: Array<{ label: string, price: number }> }} input
|
|
2813
2883
|
*/
|
|
2814
2884
|
async create({ group: group2, me }, input) {
|
|
2815
|
-
const data = this.parse(input);
|
|
2885
|
+
const data = await this.parse(input);
|
|
2816
2886
|
const order2 = await strapi.db.transaction(async () => {
|
|
2817
2887
|
const created = await orders().create({
|
|
2818
2888
|
data: {
|
|
@@ -2858,7 +2928,8 @@ const order = ({ strapi }) => {
|
|
|
2858
2928
|
lines: taken.map((l) => ({
|
|
2859
2929
|
item: idOf(l.item),
|
|
2860
2930
|
member: idOf(l.member),
|
|
2861
|
-
quantity: l.quantity
|
|
2931
|
+
quantity: l.quantity,
|
|
2932
|
+
note: l.note || null
|
|
2862
2933
|
}))
|
|
2863
2934
|
};
|
|
2864
2935
|
},
|
|
@@ -2875,7 +2946,11 @@ const order = ({ strapi }) => {
|
|
|
2875
2946
|
status: order2.status
|
|
2876
2947
|
});
|
|
2877
2948
|
},
|
|
2878
|
-
/**
|
|
2949
|
+
/**
|
|
2950
|
+
* What was sent, by item row id: how many, and the precision given with it if any. Unknown
|
|
2951
|
+
* items and odd quantities are refused.
|
|
2952
|
+
* @returns {Map<number, { quantity: number, note: string|null }>}
|
|
2953
|
+
*/
|
|
2879
2954
|
quantities(input, offered) {
|
|
2880
2955
|
const byDoc = new Map(offered.map((item) => [item.documentId, item.id]));
|
|
2881
2956
|
const list = Array.isArray(input?.lines) ? input.lines : null;
|
|
@@ -2889,7 +2964,7 @@ const order = ({ strapi }) => {
|
|
|
2889
2964
|
throw invalid(`Une quantité va de 0 à ${ORDER_MAX_QUANTITY}.`, {
|
|
2890
2965
|
max: ORDER_MAX_QUANTITY
|
|
2891
2966
|
});
|
|
2892
|
-
wanted.set(item, quantity);
|
|
2967
|
+
wanted.set(item, { quantity, note: tidy(raw?.note, ORDER_NOTE_MAX) || null });
|
|
2893
2968
|
}
|
|
2894
2969
|
return wanted;
|
|
2895
2970
|
},
|
|
@@ -2898,7 +2973,7 @@ const order = ({ strapi }) => {
|
|
|
2898
2973
|
* (someone who told them, someone without the app), and still can after the closing time.
|
|
2899
2974
|
* @param {{ group: Object, me: Object }} seat the caller's
|
|
2900
2975
|
* @param {string} documentId the order
|
|
2901
|
-
* @param {{ member?: string, lines: Array<{ item: string, quantity: number }> }} input
|
|
2976
|
+
* @param {{ member?: string, lines: Array<{ item: string, quantity: number, note?: string }> }} input
|
|
2902
2977
|
*/
|
|
2903
2978
|
async setLines({ group: group2, me }, documentId, input) {
|
|
2904
2979
|
const order2 = await this.find(group2, documentId);
|
|
@@ -2915,10 +2990,10 @@ const order = ({ strapi }) => {
|
|
|
2915
2990
|
const wanted = this.quantities(input, offered);
|
|
2916
2991
|
await strapi.db.transaction(async () => {
|
|
2917
2992
|
await lines().deleteMany({ where: { order: order2.id, member: target.id } });
|
|
2918
|
-
for (const [item, quantity] of wanted)
|
|
2993
|
+
for (const [item, { quantity, note }] of wanted)
|
|
2919
2994
|
if (quantity > 0)
|
|
2920
2995
|
await lines().create({
|
|
2921
|
-
data: { order: order2.id, item, member: target.id, quantity }
|
|
2996
|
+
data: { order: order2.id, item, member: target.id, quantity, note }
|
|
2922
2997
|
});
|
|
2923
2998
|
});
|
|
2924
2999
|
return order2;
|
|
@@ -2936,7 +3011,7 @@ const order = ({ strapi }) => {
|
|
|
2936
3011
|
this.assertOrganizer(order2, me);
|
|
2937
3012
|
if (order2.status === ORDER_STATUS.CLOSED) return order2;
|
|
2938
3013
|
this.assertOpen(order2);
|
|
2939
|
-
const { maxAmount } = svc("settings").limits();
|
|
3014
|
+
const { maxAmount } = await svc("settings").limits();
|
|
2940
3015
|
const deliveryFee = input?.deliveryFee ?? 0;
|
|
2941
3016
|
if (!Number.isInteger(deliveryFee) || deliveryFee < 0 || deliveryFee > maxAmount)
|
|
2942
3017
|
throw invalid("Frais de livraison invalides.", { maxAmount });
|
|
@@ -3033,7 +3108,7 @@ const order = ({ strapi }) => {
|
|
|
3033
3108
|
yours
|
|
3034
3109
|
};
|
|
3035
3110
|
if (!detailed) return summary;
|
|
3036
|
-
const takenBy = (member2) => taken.filter((l) => l.member === member2 && docOf.has(l.item)).map((l) => ({ item: docOf.get(l.item), quantity: l.quantity }));
|
|
3111
|
+
const takenBy = (member2) => taken.filter((l) => l.member === member2 && docOf.has(l.item)).map((l) => ({ item: docOf.get(l.item), quantity: l.quantity, note: l.note }));
|
|
3037
3112
|
const quantityOf = (item, member2) => taken.filter((l) => l.item === item && (member2 == null || l.member === member2)).reduce((sum, l) => sum + l.quantity, 0);
|
|
3038
3113
|
return {
|
|
3039
3114
|
...summary,
|
|
@@ -3051,6 +3126,60 @@ const order = ({ strapi }) => {
|
|
|
3051
3126
|
}))
|
|
3052
3127
|
};
|
|
3053
3128
|
},
|
|
3129
|
+
/**
|
|
3130
|
+
* The orders a person should know about, across their groups: the open ones, and those that
|
|
3131
|
+
* closed or were dropped within the last day. Light enough to be asked often: no books read.
|
|
3132
|
+
* @param {Object} viewer the person asking
|
|
3133
|
+
* @param {Date} [now]
|
|
3134
|
+
* @returns {Promise<Object[]>} the latest first
|
|
3135
|
+
*/
|
|
3136
|
+
async current(viewer, now = /* @__PURE__ */ new Date()) {
|
|
3137
|
+
const seats = await svc("group").seatsOf(viewer);
|
|
3138
|
+
if (seats.length === 0) return [];
|
|
3139
|
+
const seatByGroup = new Map(seats.map((s) => [s.group.id, s]));
|
|
3140
|
+
const rows = await orders().findMany({
|
|
3141
|
+
where: {
|
|
3142
|
+
group: { id: { $in: [...seatByGroup.keys()] } },
|
|
3143
|
+
$or: [
|
|
3144
|
+
{ status: ORDER_STATUS.OPEN },
|
|
3145
|
+
{ closedAt: { $gte: new Date(now.getTime() - ORDER_RECENT_MS) } }
|
|
3146
|
+
]
|
|
3147
|
+
},
|
|
3148
|
+
populate: CURRENT_POPULATE,
|
|
3149
|
+
orderBy: [{ id: "desc" }]
|
|
3150
|
+
});
|
|
3151
|
+
return Promise.all(
|
|
3152
|
+
rows.map((order2) => this.brief(order2, seatByGroup.get(idOf(order2.group)), viewer))
|
|
3153
|
+
);
|
|
3154
|
+
},
|
|
3155
|
+
/**
|
|
3156
|
+
* An order in a few facts, for someone who is not looking at it: where, whose, where it
|
|
3157
|
+
* stands and what the viewer took.
|
|
3158
|
+
* @param {Object} order `organizer.person` populated
|
|
3159
|
+
* @param {Object} me the viewer's seat, `group` populated
|
|
3160
|
+
* @param {Object} viewer the person asking
|
|
3161
|
+
*/
|
|
3162
|
+
async brief(order2, me, viewer) {
|
|
3163
|
+
const { items: offered, lines: taken } = await this.load(order2);
|
|
3164
|
+
const totals = orderTotals({ items: offered, lines: taken, deliveryFee: order2.deliveryFee });
|
|
3165
|
+
const none = { quantity: 0, subtotal: 0, delivery: 0, total: 0 };
|
|
3166
|
+
const { member: _mine, ...yours } = totals.people.find((p) => p.member === me.id) ?? none;
|
|
3167
|
+
return {
|
|
3168
|
+
id: order2.documentId,
|
|
3169
|
+
group: { id: me.group.documentId, name: me.group.name },
|
|
3170
|
+
title: order2.title,
|
|
3171
|
+
status: order2.status,
|
|
3172
|
+
openedAt: iso(order2.createdAt),
|
|
3173
|
+
closesAt: iso(order2.closesAt),
|
|
3174
|
+
closedAt: iso(order2.closedAt),
|
|
3175
|
+
acceptsOrders: this.accepts(order2),
|
|
3176
|
+
isOrganizer: idOf(order2.organizer) === me.id,
|
|
3177
|
+
organizer: order2.organizer ? svc("format").member(order2.organizer, viewer) : null,
|
|
3178
|
+
participantCount: totals.people.length,
|
|
3179
|
+
total: totals.total,
|
|
3180
|
+
yours
|
|
3181
|
+
};
|
|
3182
|
+
},
|
|
3054
3183
|
/** The group's orders as a member reads them: the open ones first, then the latest. */
|
|
3055
3184
|
async list(seat, viewer) {
|
|
3056
3185
|
const rows = await orders().findMany({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonatel-os/strapi-plugin-split",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A shared-expenses ledger for Strapi v5: groups, members, expenses split three ways, balances, settlements with idempotent writes — with admin screens and RBAC.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "LPIX-11 <mohamed.johnson@orange-sonatel.com>",
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const designSystem = require("@strapi/design-system");
|
|
5
|
-
const admin = require("@strapi/strapi/admin");
|
|
6
|
-
const api = require("./api-cwZGoKZx.js");
|
|
7
|
-
const index = require("./index-oyRhs5fN.js");
|
|
8
|
-
const Row = ({ k, v, hint }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
9
|
-
designSystem.Flex,
|
|
10
|
-
{
|
|
11
|
-
justifyContent: "space-between",
|
|
12
|
-
alignItems: "flex-start",
|
|
13
|
-
gap: 4,
|
|
14
|
-
paddingTop: 3,
|
|
15
|
-
paddingBottom: 3,
|
|
16
|
-
style: { borderBottom: "1px solid #eaeaef" },
|
|
17
|
-
children: [
|
|
18
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: 1, minWidth: 0 }, children: [
|
|
19
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", tag: "p", children: k }),
|
|
20
|
-
hint ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: hint }) : null
|
|
21
|
-
] }),
|
|
22
|
-
/* @__PURE__ */ jsxRuntime.jsx(api.Mono, { variant: "pi", fontWeight: "semiBold", children: String(v ?? "—") || "—" })
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
const SettingsPage = () => {
|
|
27
|
-
const { data, isLoading, isError } = api.useGetSettingsQuery();
|
|
28
|
-
if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Loading, {});
|
|
29
|
-
if (isError) return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {});
|
|
30
|
-
const s = data ?? {};
|
|
31
|
-
const methods = Object.entries(s.methods ?? {});
|
|
32
|
-
return /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Protect, { permissions: index.PERMISSIONS.settingsRead, children: /* @__PURE__ */ jsxRuntime.jsxs(admin.Page.Main, { children: [
|
|
33
|
-
/* @__PURE__ */ jsxRuntime.jsx(admin.Page.Title, { children: "Split · Configuration" }),
|
|
34
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
35
|
-
admin.Layouts.Header,
|
|
36
|
-
{
|
|
37
|
-
title: "Split configuration",
|
|
38
|
-
subtitle: "Read from config/plugins.js and the server environment. Nothing here is edited in the admin."
|
|
39
|
-
}
|
|
40
|
-
),
|
|
41
|
-
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
42
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
43
|
-
api.Section,
|
|
44
|
-
{
|
|
45
|
-
title: "Who is calling",
|
|
46
|
-
help: "The app routes under /api/split are protected by Strapi API tokens. The caller names the person with a header.",
|
|
47
|
-
children: [
|
|
48
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
49
|
-
Row,
|
|
50
|
-
{
|
|
51
|
-
k: "Person id header",
|
|
52
|
-
v: s.people?.idHeader,
|
|
53
|
-
hint: "Any stable id the host owns; a phone number is stored under one spelling."
|
|
54
|
-
}
|
|
55
|
-
),
|
|
56
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
-
Row,
|
|
58
|
-
{
|
|
59
|
-
k: "Display name header",
|
|
60
|
-
v: s.people?.nameHeader,
|
|
61
|
-
hint: "Optional; refreshes the person's name."
|
|
62
|
-
}
|
|
63
|
-
),
|
|
64
|
-
/* @__PURE__ */ jsxRuntime.jsx(Row, { k: "Create unknown people", v: s.people?.autoProvision ? "yes" : "no" }),
|
|
65
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
66
|
-
Row,
|
|
67
|
-
{
|
|
68
|
-
k: "Home country code",
|
|
69
|
-
v: s.countryCode,
|
|
70
|
-
hint: "Dropped from stored phone numbers."
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
]
|
|
74
|
-
}
|
|
75
|
-
),
|
|
76
|
-
/* @__PURE__ */ jsxRuntime.jsxs(api.Section, { title: "Groups and amounts", index: 1, children: [
|
|
77
|
-
/* @__PURE__ */ jsxRuntime.jsx(Row, { k: "Invite code prefix", v: s.inviteCodePrefix }),
|
|
78
|
-
/* @__PURE__ */ jsxRuntime.jsx(Row, { k: "Groups per person", v: s.limits?.maxGroupsPerPerson }),
|
|
79
|
-
/* @__PURE__ */ jsxRuntime.jsx(Row, { k: "Members per group", v: s.limits?.maxMembersPerGroup }),
|
|
80
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
81
|
-
Row,
|
|
82
|
-
{
|
|
83
|
-
k: "Largest amount",
|
|
84
|
-
v: s.limits?.maxAmount,
|
|
85
|
-
hint: "One expense or one settlement, in the currency's smallest unit."
|
|
86
|
-
}
|
|
87
|
-
)
|
|
88
|
-
] }),
|
|
89
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
-
api.Section,
|
|
91
|
-
{
|
|
92
|
-
title: "Settlement methods",
|
|
93
|
-
help: "An instant method is one the host pays itself: it is confirmed at once. The others wait for the receiver.",
|
|
94
|
-
index: 2,
|
|
95
|
-
children: methods.map(([name, m]) => /* @__PURE__ */ jsxRuntime.jsx(Row, { k: name, v: m.instant ? "instant" : "receiver confirms" }, name))
|
|
96
|
-
}
|
|
97
|
-
)
|
|
98
|
-
] }) })
|
|
99
|
-
] }) });
|
|
100
|
-
};
|
|
101
|
-
exports.SettingsPage = SettingsPage;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Flex, Box, Typography } from "@strapi/design-system";
|
|
3
|
-
import { Page, Layouts } from "@strapi/strapi/admin";
|
|
4
|
-
import { m as useGetSettingsQuery, b as Section, M as Mono } from "./api-BCYZ56eI.mjs";
|
|
5
|
-
import { a as PERMISSIONS } from "./index-PFbwTznf.mjs";
|
|
6
|
-
const Row = ({ k, v, hint }) => /* @__PURE__ */ jsxs(
|
|
7
|
-
Flex,
|
|
8
|
-
{
|
|
9
|
-
justifyContent: "space-between",
|
|
10
|
-
alignItems: "flex-start",
|
|
11
|
-
gap: 4,
|
|
12
|
-
paddingTop: 3,
|
|
13
|
-
paddingBottom: 3,
|
|
14
|
-
style: { borderBottom: "1px solid #eaeaef" },
|
|
15
|
-
children: [
|
|
16
|
-
/* @__PURE__ */ jsxs(Box, { style: { flex: 1, minWidth: 0 }, children: [
|
|
17
|
-
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", tag: "p", children: k }),
|
|
18
|
-
hint ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: hint }) : null
|
|
19
|
-
] }),
|
|
20
|
-
/* @__PURE__ */ jsx(Mono, { variant: "pi", fontWeight: "semiBold", children: String(v ?? "—") || "—" })
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
const SettingsPage = () => {
|
|
25
|
-
const { data, isLoading, isError } = useGetSettingsQuery();
|
|
26
|
-
if (isLoading) return /* @__PURE__ */ jsx(Page.Loading, {});
|
|
27
|
-
if (isError) return /* @__PURE__ */ jsx(Page.Error, {});
|
|
28
|
-
const s = data ?? {};
|
|
29
|
-
const methods = Object.entries(s.methods ?? {});
|
|
30
|
-
return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.settingsRead, children: /* @__PURE__ */ jsxs(Page.Main, { children: [
|
|
31
|
-
/* @__PURE__ */ jsx(Page.Title, { children: "Split · Configuration" }),
|
|
32
|
-
/* @__PURE__ */ jsx(
|
|
33
|
-
Layouts.Header,
|
|
34
|
-
{
|
|
35
|
-
title: "Split configuration",
|
|
36
|
-
subtitle: "Read from config/plugins.js and the server environment. Nothing here is edited in the admin."
|
|
37
|
-
}
|
|
38
|
-
),
|
|
39
|
-
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
40
|
-
/* @__PURE__ */ jsxs(
|
|
41
|
-
Section,
|
|
42
|
-
{
|
|
43
|
-
title: "Who is calling",
|
|
44
|
-
help: "The app routes under /api/split are protected by Strapi API tokens. The caller names the person with a header.",
|
|
45
|
-
children: [
|
|
46
|
-
/* @__PURE__ */ jsx(
|
|
47
|
-
Row,
|
|
48
|
-
{
|
|
49
|
-
k: "Person id header",
|
|
50
|
-
v: s.people?.idHeader,
|
|
51
|
-
hint: "Any stable id the host owns; a phone number is stored under one spelling."
|
|
52
|
-
}
|
|
53
|
-
),
|
|
54
|
-
/* @__PURE__ */ jsx(
|
|
55
|
-
Row,
|
|
56
|
-
{
|
|
57
|
-
k: "Display name header",
|
|
58
|
-
v: s.people?.nameHeader,
|
|
59
|
-
hint: "Optional; refreshes the person's name."
|
|
60
|
-
}
|
|
61
|
-
),
|
|
62
|
-
/* @__PURE__ */ jsx(Row, { k: "Create unknown people", v: s.people?.autoProvision ? "yes" : "no" }),
|
|
63
|
-
/* @__PURE__ */ jsx(
|
|
64
|
-
Row,
|
|
65
|
-
{
|
|
66
|
-
k: "Home country code",
|
|
67
|
-
v: s.countryCode,
|
|
68
|
-
hint: "Dropped from stored phone numbers."
|
|
69
|
-
}
|
|
70
|
-
)
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
),
|
|
74
|
-
/* @__PURE__ */ jsxs(Section, { title: "Groups and amounts", index: 1, children: [
|
|
75
|
-
/* @__PURE__ */ jsx(Row, { k: "Invite code prefix", v: s.inviteCodePrefix }),
|
|
76
|
-
/* @__PURE__ */ jsx(Row, { k: "Groups per person", v: s.limits?.maxGroupsPerPerson }),
|
|
77
|
-
/* @__PURE__ */ jsx(Row, { k: "Members per group", v: s.limits?.maxMembersPerGroup }),
|
|
78
|
-
/* @__PURE__ */ jsx(
|
|
79
|
-
Row,
|
|
80
|
-
{
|
|
81
|
-
k: "Largest amount",
|
|
82
|
-
v: s.limits?.maxAmount,
|
|
83
|
-
hint: "One expense or one settlement, in the currency's smallest unit."
|
|
84
|
-
}
|
|
85
|
-
)
|
|
86
|
-
] }),
|
|
87
|
-
/* @__PURE__ */ jsx(
|
|
88
|
-
Section,
|
|
89
|
-
{
|
|
90
|
-
title: "Settlement methods",
|
|
91
|
-
help: "An instant method is one the host pays itself: it is confirmed at once. The others wait for the receiver.",
|
|
92
|
-
index: 2,
|
|
93
|
-
children: methods.map(([name, m]) => /* @__PURE__ */ jsx(Row, { k: name, v: m.instant ? "instant" : "receiver confirms" }, name))
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
] }) })
|
|
97
|
-
] }) });
|
|
98
|
-
};
|
|
99
|
-
export {
|
|
100
|
-
SettingsPage
|
|
101
|
-
};
|