@jsb188/mday 1.1.4

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/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@jsb188/mday",
3
+ "version": "1.1.4",
4
+ "description": "Mday specific functions and constants.",
5
+ "license": "ISC",
6
+ "author": "jsb188",
7
+ "type": "module",
8
+ "exports": {
9
+ "./constants/log": "./src/constants/log.ts",
10
+ "./schemas/queryString": "./src/schemas/queryString.ts",
11
+ "./types/log.d": "./src/types/log.d.ts",
12
+ "./utils/log": "./src/utils/log.ts"
13
+ },
14
+ "dependencies": {
15
+ "zod": "^3.25.67"
16
+ },
17
+ "scripts": {
18
+ "test": "echo \"Error: no test specified\" && exit 1"
19
+ }
20
+ }
@@ -0,0 +1,192 @@
1
+ import type { LogArableTypeEnum } from '../types/log.d.ts';
2
+
3
+ // Arable farming logs
4
+
5
+ export const ARABLE_ACTIVITIES_GROUPED = [
6
+ [
7
+ 'SEED',
8
+ [
9
+ 'SEED_PURCHASE_INFO',
10
+ 'SEED_COMPLIANCE_NOTE',
11
+ 'OTHER_SEED_ACTIVITY',
12
+ ]
13
+ ],
14
+ [
15
+ 'FIELD',
16
+ [
17
+ 'PREPARE_SOIL',
18
+ 'PLANTING',
19
+ 'IRRIGATION',
20
+ 'FERTILIZATION_COMPOST',
21
+ 'PROTECT_CROP',
22
+ 'MONITOR_CROP',
23
+ 'PRUNING',
24
+ 'STRUCTURE_MAINTENANCE',
25
+ 'PREPARE_HARVEST',
26
+ 'OTHER_FIELD_ACTIVITY',
27
+ ]
28
+ ],
29
+ [
30
+ 'HARVEST',
31
+ [
32
+ 'HARVEST_CROP',
33
+ 'HARVEST_COUNT',
34
+ 'SORT_GRADE',
35
+ 'YIELD_LOSS_ESTIMATE',
36
+ 'OTHER_HARVEST_ACTIVITY',
37
+ ]
38
+ ],
39
+ [
40
+ 'POST_HARVEST',
41
+ [
42
+ 'POST_HARVEST_HANDLING',
43
+ 'POST_HARVEST_PACKAGING',
44
+ 'OTHER_POST_HARVEST_ACTIVITY',
45
+ ]
46
+ ],
47
+ [
48
+ 'SALES',
49
+ [
50
+ 'SALE_TRANSACTION',
51
+ 'SALE_DETAILS',
52
+ 'SALE_FEEDBACK',
53
+ 'OTHER_SALES_ACTIVITY',
54
+ ]
55
+ ]
56
+ ] as [LogArableTypeEnum, string[]][];
57
+
58
+ export const LOG_ARABLE_ACTIVITY_ENUMS = ARABLE_ACTIVITIES_GROUPED.reduce(
59
+ (acc, a) => acc.concat(a[1]),
60
+ [] as string[]
61
+ );
62
+
63
+ // All log types for all activities
64
+
65
+ export const LOG_TYPE_ENUMS = [
66
+ ...ARABLE_ACTIVITIES_GROUPED.map(a => a[0]),
67
+ ];
68
+
69
+ export const LOG_ACTIVITY_ENUMS = [
70
+ ...LOG_ARABLE_ACTIVITY_ENUMS
71
+ ];
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+ export const JOURNAL_TYPES_TO_TEXT = {
88
+ SEED: 'seed purchases',
89
+ FIELD: 'field activities',
90
+ HARVEST: 'harvest activities',
91
+ POST_HARVEST: 'handling, washing, sorting, grading, packaging after harvest',
92
+ SALES: 'sales',
93
+ };
94
+
95
+ export const TEXT_TO_JOURNAL_TYPES = Object.fromEntries(
96
+ Object.entries(JOURNAL_TYPES_TO_TEXT).map(([key, value]) => [value, key]),
97
+ ) as Record<string, string>;
98
+
99
+ /**
100
+ * Activities for each journal types
101
+ */
102
+
103
+ export const SEED_LOG_ACTIVITY_ENUMS = [
104
+ 'SEED_PURCHASE_INFO',
105
+ 'SEED_COMPLIANCE_NOTE',
106
+ 'OTHER_SEED_ACTIVITY',
107
+ ] as const;
108
+
109
+ export const FIELD_LOG_ACTIVITY_ENUMS = [
110
+ 'PREPARE_SOIL',
111
+ 'PLANTING',
112
+ 'IRRIGATION',
113
+ 'FERTILIZATION_COMPOST',
114
+ 'PROTECT_CROP',
115
+ 'MONITOR_CROP',
116
+ 'PRUNING',
117
+ 'STRUCTURE_MAINTENANCE',
118
+ 'PREPARE_HARVEST',
119
+ 'OTHER_FIELD_ACTIVITY',
120
+ ] as const;
121
+
122
+ export const HARVEST_LOG_ACTIVITY_ENUMS = [
123
+ 'HARVEST_CROP',
124
+ 'HARVEST_COUNT',
125
+ 'SORT_GRADE',
126
+ 'YIELD_LOSS_ESTIMATE',
127
+ 'OTHER_HARVEST_ACTIVITY',
128
+ ] as const;
129
+
130
+ export const POST_HARVEST_LOG_ACTIVITY_ENUMS = [
131
+ 'POST_HARVEST_HANDLING',
132
+ 'POST_HARVEST_PACKAGING',
133
+ 'OTHER_POST_HARVEST_ACTIVITY',
134
+ ] as const;
135
+
136
+ export const SALES_LOG_ACTIVITY_ENUMS = [
137
+ 'SALE_TRANSACTION',
138
+ 'SALE_DETAILS',
139
+ 'SALE_FEEDBACK',
140
+ 'OTHER_SALES_ACTIVITY',
141
+ ] as const;
142
+
143
+ /**
144
+ * Activity enums to text
145
+ */
146
+
147
+ export const JOURNAL_ACTIVITIES_TO_TEXT = {
148
+ // # Seed log activities
149
+ SEED_PURCHASE_INFO: 'seed purchase information',
150
+ SEED_COMPLIANCE_NOTE: 'seed compliance notes',
151
+ OTHER_SEED_ACTIVITY: 'other seed purchase related notes',
152
+
153
+ // # Field log activities
154
+ PREPARE_SOIL: 'soil, beds preparation',
155
+ PLANTING: 'seeding, transplanting',
156
+ IRRIGATION: 'irrigation management',
157
+ FERTILIZATION_COMPOST: 'fertilization, compost application',
158
+ PROTECT_CROP: 'weed, pest, disease management',
159
+ MONITOR_CROP: 'crop monitoring',
160
+ PRUNING: 'pruning',
161
+ STRUCTURE_MAINTENANCE: 'trellising, structure maintenance',
162
+ PREPARE_HARVEST: 'preparing crops for harvest',
163
+ OTHER_FIELD_ACTIVITY: 'other field activities',
164
+
165
+ // # Harvest log activities
166
+ HARVEST_CROP: 'harvesting crops',
167
+ HARVEST_COUNT: 'counting, weighing harvested crops',
168
+ SORT_GRADE: 'sorting, grading crops',
169
+ YIELD_LOSS_ESTIMATE: 'estimating yield or loss',
170
+ OTHER_HARVEST_ACTIVITY: 'other harvest activities',
171
+
172
+ // # Post-harvest log activities
173
+ POST_HARVEST_HANDLING: 'washing, drying, trimming, sorting, or grading produce',
174
+ POST_HARVEST_PACKAGING: 'packaging, cooling, or moving produce to storage',
175
+ OTHER_POST_HARVEST_ACTIVITY: 'other post-harvest activities',
176
+
177
+ // # Sales log activities
178
+ SALE_TRANSACTION: 'sale transactions',
179
+ SALE_DETAILS: 'sale details',
180
+ SALE_FEEDBACK: 'sale feedback or issues',
181
+ OTHER_SALES_ACTIVITY: 'other sales related notes',
182
+ };
183
+
184
+ export const TEXT_TO_JOURNAL_ACTIVITIES = Object.fromEntries(
185
+ Object.entries(JOURNAL_ACTIVITIES_TO_TEXT).map(([key, value]) => [value, key]),
186
+ ) as Record<string, string>;
187
+
188
+ // Moved to walk-in
189
+ // Hydrocooled immediately after harvest
190
+ // Bagged and labeled greens
191
+ // Packed in clamshells
192
+ // Stickered with farm logo
File without changes
@@ -0,0 +1,45 @@
1
+ import { LOG_ARABLE_ACTIVITY_ENUMS } from '../constants/log.ts';
2
+ import type { OrganizationOperationEnum } from './organization.d.ts';
3
+
4
+ // All logs types
5
+
6
+ export type LogArableTypeEnum = 'SEED' | 'FIELD' | 'HARVEST' | 'POST_HARVEST' | 'SALES';
7
+ export type LogTypeEnum = LogArableTypeEnum;
8
+
9
+ // All logs activities
10
+
11
+ export type LogArableActivityEnum = typeof LOG_ARABLE_ACTIVITY_ENUMS[number];
12
+ export type LogActivityEnum = LogArableActivityEnum;
13
+
14
+ // Log entry object
15
+
16
+ export interface LogArableObj {
17
+ type: LogTypeEnum;
18
+ activity: LogArableActivityEnum;
19
+ item?: string;
20
+ quantity?: number;
21
+ unit?: string;
22
+ price?: number;
23
+ notes: string | null;
24
+ }
25
+
26
+ export interface LogEntryGQLData {
27
+ id: string
28
+ accountId: string
29
+ organizationId: string
30
+ details: LogArableObj;
31
+
32
+ account: any;
33
+ createdAt: string // ISO date string
34
+ updatedAt: string // ISO date string
35
+ }
36
+
37
+ // Filters for search
38
+
39
+ export interface FilterLogEntriesArgs {
40
+ operation: OrganizationOperationEnum;
41
+ type?: LogTypeEnum | null;
42
+ startDate?: string | null;
43
+ endDate?: string | null;
44
+ query?: string;
45
+ }
@@ -0,0 +1,66 @@
1
+ import { textWithBrackets, ucFirst } from '../utils/string';
2
+ import { ARABLE_ACTIVITIES_GROUPED } from '../constants/log';
3
+ import type { OrganizationOperationEnum } from '../types/organization.d';
4
+ import type { ColorEnum } from '../types/app';
5
+ import type { LogTypeEnum } from '../types/log';
6
+
7
+ /**
8
+ * Map journal type to a color
9
+ * @param type - The type of the log entry
10
+ * @returns The color associated with the journal type
11
+ */
12
+
13
+ export function getJournalTypeColor(type: LogTypeEnum): ColorEnum {
14
+ const journalTypeToColor = {
15
+ SEED: 'brown',
16
+ FIELD: 'yellow',
17
+ HARVEST: 'green',
18
+ POST_HARVEST: 'cyan',
19
+ SALES: 'blue',
20
+ } as Record<LogTypeEnum, ColorEnum>;
21
+
22
+ // Default to zinc if type is not found
23
+ const color = journalTypeToColor[type] || 'zinc';
24
+ return color;
25
+ }
26
+
27
+ /**
28
+ * Get the title for log entry for each Union interface
29
+ * @param details - The details Union interface for log entry
30
+ * @return The title for the log entry
31
+ */
32
+
33
+ export function getLogEntryTitle(details: any): string {
34
+ const { __typename, __table } = details;
35
+ switch (__typename || __table) {
36
+ case 'logs_arable':
37
+ case 'LogEntryArable': {
38
+ return textWithBrackets(ucFirst(details.crop?.name || details.product?.name), [details.quantity, details.unit]);
39
+ }
40
+ case 'logs_livestock':
41
+ case 'LogEntryLivestock': {
42
+ // .. live stock logs here ..
43
+ }
44
+ default:
45
+ }
46
+ return '..';
47
+ }
48
+
49
+ /**
50
+ * Get log type from activity; bassed on organization's industry-based operation
51
+ * @param operation - The operation of the organization
52
+ * @param activity - The activity of the log entry
53
+ * @returns The log type or null if not found
54
+ */
55
+
56
+ export function getLogTypeFromActivity(operation: OrganizationOperationEnum, activity: any) {
57
+ switch (operation) {
58
+ case 'ARABLE':
59
+ return ARABLE_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity))?.[0] || null;
60
+ case 'LIVESTOCK':
61
+ return null; // Livestock activities are not defined in this context
62
+ default:
63
+ console.warn('(!1) Cannot get log type from unknown operation type:', operation);
64
+ return null;
65
+ }
66
+ }