@simitgroup/simpleapp-generator 2.0.2-z-alpha → 2.0.3-b-alpha
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/ReleaseNote.md +7 -2
- package/package.json +3 -3
- package/templates/basic/nest/controller.ts.eta +11 -0
- package/templates/nest/src/simple-app/_core/features/profile/profile.schema.ts.eta +2 -0
- package/templates/nest/src/simple-app/_core/features/user-context/user.context.ts.eta +4 -1
- package/templates/nest/src/simple-app/_core/framework/base/simple-app.controller.ts.eta +5 -0
- package/templates/nuxt/composables/date.generate.ts.eta +33 -10
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +3 -0
package/ReleaseNote.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
[2.0.
|
|
2
|
-
1. Add
|
|
1
|
+
[2.0.3b-alpha]
|
|
2
|
+
1. Add dateformat in user context
|
|
3
|
+
2. Add allow downloads
|
|
4
|
+
3. Add getTimezoneOffsetMinutesByTimeZone (minutes to add to local time to get UTC, which flips the sign)
|
|
5
|
+
|
|
6
|
+
[2.0.3a-alpha]
|
|
7
|
+
1. Add createMany controller for all nestJs resources
|
|
3
8
|
|
|
4
9
|
[2.0.2y-alpha]
|
|
5
10
|
1. Add utcToLocalOffset function
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simitgroup/simpleapp-generator",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3b-alpha",
|
|
4
4
|
"description": "frontend nuxtjs and backend nests code generator using jsonschema.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"simpleapp-generator": "dist/index.js"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^20.
|
|
45
|
+
"@types/node": "^20.19.39",
|
|
46
46
|
"prettier": "^3.0.2",
|
|
47
|
-
"typescript": "^5.
|
|
47
|
+
"typescript": "^5.9.3"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -212,6 +212,17 @@ export class <%= it.typename %>Controller extends SimpleAppController<
|
|
|
212
212
|
return await this._update(appuser,id, data) ;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
@Post('bulk-create')
|
|
216
|
+
@Roles(Role.SuperAdmin, Role.SuperUser, Role.<%= it.typename%>_create)
|
|
217
|
+
@ApiResponse({ status: 201,description: 'success',type: [schemas.<%= it.typename%>] })
|
|
218
|
+
@ApiResponse({ status: 400, description: 'bad request' })
|
|
219
|
+
@ApiResponse({ status: 500, description: 'internal error' })
|
|
220
|
+
@ApiBody({ description: 'Data', type: [schemas.<%= it.typename%>] })
|
|
221
|
+
@ApiOperation({ operationId: 'runCreateMany' })
|
|
222
|
+
async createMany(@AppUser() appuser: UserContext, @Body() data: schemas.<%= it.typename%>[]) {
|
|
223
|
+
return await this._createMany(appuser, data);
|
|
224
|
+
}
|
|
225
|
+
|
|
215
226
|
@Patch('bulk-patch')
|
|
216
227
|
@ApiResponse({ status: 200, description: 'success', type: schemas.UpdateManyResponse})
|
|
217
228
|
@Roles(Role.SuperAdmin, Role.SuperUser, Role.<%= it.typename%>_update)
|
|
@@ -352,7 +352,7 @@ export class UserContext extends UserContextInfo {
|
|
|
352
352
|
as: 'o',
|
|
353
353
|
localField: 'orgId',
|
|
354
354
|
foreignField: 'orgId',
|
|
355
|
-
pipeline: [{ $project: { orgCode: 1, orgName: 1, offsetMinute: 1, timeZone: 1, currency: 1, country: 1 } }],
|
|
355
|
+
pipeline: [{ $project: { orgCode: 1, orgName: 1, offsetMinute: 1, timeZone: 1, currency: 1, country: 1, dateFormat: 1 } }],
|
|
356
356
|
},
|
|
357
357
|
},
|
|
358
358
|
{
|
|
@@ -542,6 +542,7 @@ export class UserContext extends UserContextInfo {
|
|
|
542
542
|
this.timeZone = userProfile['timeZone'] ?? '';
|
|
543
543
|
this.currency = userProfile['currency'] ?? '';
|
|
544
544
|
this.country = userProfile['country'] ?? '';
|
|
545
|
+
this.dateFormat = userProfile['dateFormat'] ?? '';
|
|
545
546
|
this.offsetMinute = userProfile['offsetMinute'] ?? 0;
|
|
546
547
|
this.orgRecordId = userProfile['orgRecordId'] ?? '';
|
|
547
548
|
this.branchRecordId = userProfile['branchRecordId'] ?? '';
|
|
@@ -800,6 +801,7 @@ export class UserContext extends UserContextInfo {
|
|
|
800
801
|
timeZone: this.timeZone,
|
|
801
802
|
currency: this.currency,
|
|
802
803
|
country: this.country,
|
|
804
|
+
dateFormat: this.dateFormat,
|
|
803
805
|
//offset in minute, malaysia -480
|
|
804
806
|
offsetMinute: this.offsetMinute,
|
|
805
807
|
email: this.email,
|
|
@@ -1157,6 +1159,7 @@ export class UserContext extends UserContextInfo {
|
|
|
1157
1159
|
this.timeZone = userProfile['timeZone'] ?? '';
|
|
1158
1160
|
this.currency = userProfile['currency'] ?? '';
|
|
1159
1161
|
this.country = userProfile['country'] ?? '';
|
|
1162
|
+
this.dateFormat = userProfile['dateFormat'] ?? '';
|
|
1160
1163
|
this.offsetMinute = userProfile['offsetMinute'] ?? 0;
|
|
1161
1164
|
this.orgRecordId = userProfile['orgRecordId'] ?? '';
|
|
1162
1165
|
this.branchRecordId = userProfile['branchRecordId'] ?? '';
|
|
@@ -29,6 +29,7 @@ type ServiceType = {
|
|
|
29
29
|
setData: Function;
|
|
30
30
|
getAutoComplete: Function;
|
|
31
31
|
fullTextSearch: Function;
|
|
32
|
+
createMany: Function;
|
|
32
33
|
patchMany: Function;
|
|
33
34
|
};
|
|
34
35
|
|
|
@@ -94,6 +95,10 @@ export class SimpleAppController<TService extends ServiceType, TApiSchema> {
|
|
|
94
95
|
return this.service.findIdThenDelete(appuser, id);
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
async _createMany(appuser: UserContext, data: TApiSchema[]) {
|
|
99
|
+
return this.service.createMany(appuser, data) as TApiSchema[];
|
|
100
|
+
}
|
|
101
|
+
|
|
97
102
|
async _patchMany(appuser: UserContext, patchManyData: PatchManyRequest<TApiSchema>) {
|
|
98
103
|
return this.service.patchMany(appuser, patchManyData);
|
|
99
104
|
}
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* last change 2024-04-13
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
+
import { DateTime } from "luxon";
|
|
8
|
+
import {
|
|
9
|
+
dayjsDateFormatToPrimeVue,
|
|
10
|
+
getDefaultDateFormatForCountryCode,
|
|
11
|
+
} from "~/simpleapp/generate/share-libs";
|
|
7
12
|
import { DurationType } from "~/types";
|
|
8
13
|
|
|
9
14
|
const convertToDate = (date: Date | string) => {
|
|
@@ -13,20 +18,24 @@ const convertToDate = (date: Date | string) => {
|
|
|
13
18
|
//after review
|
|
14
19
|
export const today = () => useDayjs()().format("YYYY-MM-DD");
|
|
15
20
|
|
|
21
|
+
export const formatDateByOrgFormat = (date: Date | string) =>
|
|
22
|
+
useDayjs()(date).format(getDateFormat());
|
|
23
|
+
|
|
24
|
+
export const formatDateTimeByOrgFormat = (date: Date | string) =>
|
|
25
|
+
useDayjs()(date).format(getDateTimeFormat());
|
|
26
|
+
|
|
16
27
|
/**
|
|
17
28
|
* convert date object or ISO8601 date become local datetime string
|
|
18
29
|
* @param date date|string
|
|
19
30
|
* @returns local shortform date-time
|
|
20
31
|
*/
|
|
21
|
-
export const dateRenderToDateTimeStr = (date: Date | string) =>
|
|
22
|
-
convertToDate(date).toLocaleString().replace(",", " ").slice(0, -3);
|
|
32
|
+
export const dateRenderToDateTimeStr = (date: Date | string) => formatDateTimeByOrgFormat(date);
|
|
23
33
|
/**
|
|
24
34
|
* convert date object or ISO datestring become local date string
|
|
25
35
|
* @param date date|string
|
|
26
36
|
* @returns local short form date
|
|
27
37
|
*/
|
|
28
|
-
export const dateRenderToDateStr = (date: Date | string) =>
|
|
29
|
-
convertToDate(date).toLocaleDateString().replace(",", " ");
|
|
38
|
+
export const dateRenderToDateStr = (date: Date | string) => formatDateByOrgFormat(date);
|
|
30
39
|
/**
|
|
31
40
|
* convert date object or ISO datestring become time string (without seconds)
|
|
32
41
|
* @param date date|string
|
|
@@ -116,14 +125,17 @@ export const toUTCDate = (date: string | Date) => useDayjs().utc(date).format(ge
|
|
|
116
125
|
export const toUTCDateTime = (date: string | Date) =>
|
|
117
126
|
useDayjs().utc(date).format(getDateTimeFormat());
|
|
118
127
|
export const toUTCTime = (date: string | Date) => useDayjs().utc(date).format("HH:mm");
|
|
119
|
-
export const getDateFormat = (): string =>
|
|
120
|
-
|
|
128
|
+
export const getDateFormat = (): string => {
|
|
129
|
+
const profile = getUserProfile();
|
|
130
|
+
const orgDateFormat = profile?.orgInfo?.dateFormat?.trim();
|
|
131
|
+
if (orgDateFormat) return orgDateFormat;
|
|
132
|
+
return getDefaultDateFormatForCountryCode(profile?.country);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const getDateTimeFormat = (): string => `${getDateFormat()} HH:mm`;
|
|
121
136
|
export const calculateHourDifferent = (date1: Date, date2: Date) =>
|
|
122
137
|
(date1.getTime() - date2.getTime()) / 60 / 60 / 1000;
|
|
123
|
-
export const getPrimevueCalendarDateFormat = () =>
|
|
124
|
-
const country = <string>getUserProfile()?.country;
|
|
125
|
-
return "dd/mm/yy";
|
|
126
|
-
};
|
|
138
|
+
export const getPrimevueCalendarDateFormat = () => dayjsDateFormatToPrimeVue(getDateFormat());
|
|
127
139
|
|
|
128
140
|
export const addTime = (date: Date | string, duration: number, unit: DurationType) =>
|
|
129
141
|
getDayJs()(date).add(duration, "hour").toDate();
|
|
@@ -131,3 +143,14 @@ export const addTime = (date: Date | string, duration: number, unit: DurationTyp
|
|
|
131
143
|
export const utcToLocalOffset = (utcTime: string, timeZoneOffset: number) => {
|
|
132
144
|
return useDayjs().utc(utcTime).utcOffset(Number(timeZoneOffset));
|
|
133
145
|
};
|
|
146
|
+
|
|
147
|
+
export const getOffsetMinutesTimeZone = (timeZone: string, date: Date = new Date()): number => {
|
|
148
|
+
try {
|
|
149
|
+
// Keep JS Date.getTimezoneOffset sign convention:
|
|
150
|
+
// UTC+7 => -420, UTC-5 => 300
|
|
151
|
+
const luxonOffset = DateTime.fromJSDate(date).setZone(timeZone).offset;
|
|
152
|
+
return luxonOffset * -1;
|
|
153
|
+
} catch {
|
|
154
|
+
return new Date().getTimezoneOffset();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
@@ -36,6 +36,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
36
36
|
timeZone: ref(""),
|
|
37
37
|
currency: ref(""),
|
|
38
38
|
country: ref(""),
|
|
39
|
+
dateFormat: ref(""),
|
|
39
40
|
offsetMinute: ref(0),
|
|
40
41
|
tenantInfo: ref<Tenant>({} as Tenant),
|
|
41
42
|
orgInfo: ref<Organization>({} as Organization),
|
|
@@ -105,6 +106,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
105
106
|
this.timeZone = res.timeZone;
|
|
106
107
|
this.currency = res.currency;
|
|
107
108
|
this.country = res.country;
|
|
109
|
+
this.dateFormat = res.dateFormat ?? "";
|
|
108
110
|
this.offsetMinute = res.offsetMinute;
|
|
109
111
|
this.tenantInfo = res?.tenantInfo;
|
|
110
112
|
this.orgInfo = res?.orgInfo;
|
|
@@ -313,6 +315,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
313
315
|
currency: this.currency,
|
|
314
316
|
timeZone: this.timeZone,
|
|
315
317
|
country: this.country,
|
|
318
|
+
dateFormat: this.dateFormat,
|
|
316
319
|
offsetMinute: this.offsetMinute,
|
|
317
320
|
tenantInfo: this.tenantInfo,
|
|
318
321
|
orgInfo: this.orgInfo,
|