@simitgroup/simpleapp-generator 2.0.3-a-alpha → 2.0.3-c-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 +10 -0
- package/package.json +1 -1
- package/templates/nest/src/simple-app/_core/features/profile/profile.schema.ts.eta +2 -0
- package/templates/nest/src/simple-app/_core/features/profile/profile.service.ts.eta +15 -18
- package/templates/nest/src/simple-app/_core/features/user-context/user.context.ts.eta +4 -1
- package/templates/nest/src/simple-app/_core/framework/simple-app.interceptor.ts.eta +2 -1
- package/templates/nest/src/simple-app/_core/utils/string-utils.ts.eta +26 -3
- package/templates/nuxt/composables/date.generate.ts.eta +33 -10
- package/templates/nuxt/composables/getDocument.generate.ts.eta +48 -37
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +3 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppPageIframe.vue.eta +1 -1
package/ReleaseNote.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
[2.0.3c-alpha]
|
|
2
|
+
1. Remove profile service default data
|
|
3
|
+
2. Fix simple app intercepter cannot capture correct error message
|
|
4
|
+
3. Add various string utils
|
|
5
|
+
|
|
6
|
+
[2.0.3b-alpha]
|
|
7
|
+
1. Add dateformat in user context
|
|
8
|
+
2. Add allow downloads
|
|
9
|
+
3. Add getTimezoneOffsetMinutesByTimeZone (minutes to add to local time to get UTC, which flips the sign)
|
|
10
|
+
|
|
1
11
|
[2.0.3a-alpha]
|
|
2
12
|
1. Add createMany controller for all nestJs resources
|
|
3
13
|
|
package/package.json
CHANGED
|
@@ -4,27 +4,25 @@
|
|
|
4
4
|
* Author: Ks Tan
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
|
7
8
|
import countrytimezone from 'countries-and-timezones';
|
|
8
|
-
import countryToCurrency
|
|
9
|
-
import { Injectable, Scope, Inject, Logger, BadRequestException, InternalServerErrorException } from '@nestjs/common';
|
|
9
|
+
import countryToCurrency from 'country-to-currency';
|
|
10
10
|
import { UserContext } from '../user-context/user.context';
|
|
11
11
|
// import { RegTenant } from './profile.types';
|
|
12
|
-
import * as mongoose from 'mongoose';
|
|
13
|
-
import { InjectConnection } from '@nestjs/mongoose';
|
|
14
|
-
import { TenantService } from '../../resources/tenant/tenant.service';
|
|
15
|
-
import { OrganizationService } from '../../resources/organization/organization.service';
|
|
16
12
|
import { BranchService } from '../../resources/branch/branch.service';
|
|
17
|
-
import {
|
|
13
|
+
import { OrganizationService } from '../../resources/organization/organization.service';
|
|
18
14
|
import { PermissionService } from '../../resources/permission/permission.service';
|
|
15
|
+
import { TenantService } from '../../resources/tenant/tenant.service';
|
|
16
|
+
import { UserService } from '../../resources/user/user.service';
|
|
19
17
|
|
|
20
|
-
import { Tenant } from '../../resources/tenant/tenant.schema';
|
|
21
|
-
import { Organization } from '../../resources/organization/organization.schema';
|
|
22
18
|
import { Branch } from '../../resources/branch/branch.schema';
|
|
23
|
-
import {
|
|
19
|
+
import { Organization } from '../../resources/organization/organization.schema';
|
|
24
20
|
import { KeyValue, Permission } from '../../resources/permission/permission.schema';
|
|
21
|
+
import { Tenant } from '../../resources/tenant/tenant.schema';
|
|
22
|
+
import { User } from '../../resources/user/user.schema';
|
|
25
23
|
|
|
26
|
-
import { UserContextInfo } from './profile.schema';
|
|
27
24
|
import { PhotoService } from 'src/simple-app/features/upload-file/photo/photo.service';
|
|
25
|
+
import { UserContextInfo } from './profile.schema';
|
|
28
26
|
const Base64URL = require('@darkwolf/base64url');
|
|
29
27
|
@Injectable()
|
|
30
28
|
export class ProfileService {
|
|
@@ -90,13 +88,12 @@ export class ProfileService {
|
|
|
90
88
|
async createTenant(appuser: UserContext, tenantName: string, timeZone: string, utcOffset: number, businessType: string, mobileNo: string, interestedInSales?: boolean) {
|
|
91
89
|
// try{
|
|
92
90
|
|
|
93
|
-
|
|
94
91
|
const timezonedata = countrytimezone.getCountriesForTimezone(timeZone)[0];
|
|
95
92
|
const countryCode = timezonedata['id'];
|
|
96
93
|
const countryName = timezonedata['name'];
|
|
97
94
|
const currencyCode = countryToCurrency[countryCode];
|
|
98
95
|
|
|
99
|
-
appuser.startTransaction()
|
|
96
|
+
appuser.startTransaction();
|
|
100
97
|
const tenantdata: Tenant = {
|
|
101
98
|
tenantId: 1,
|
|
102
99
|
tenantName: tenantName,
|
|
@@ -159,13 +156,13 @@ export class ProfileService {
|
|
|
159
156
|
workEnd: '22:00:00',
|
|
160
157
|
workingHours: [],
|
|
161
158
|
offdays: ['sat', 'sun'],
|
|
162
|
-
street1: '
|
|
163
|
-
street2: '
|
|
164
|
-
postcode: '
|
|
165
|
-
city: '
|
|
159
|
+
street1: '',
|
|
160
|
+
street2: '',
|
|
161
|
+
postcode: '',
|
|
162
|
+
city: '',
|
|
166
163
|
tel: mobileNo,
|
|
167
164
|
email: appuser.getEmail(),
|
|
168
|
-
region: '
|
|
165
|
+
region: '',
|
|
169
166
|
country: countryName,
|
|
170
167
|
active: true,
|
|
171
168
|
orgId: orgResult.orgId,
|
|
@@ -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'] ?? '';
|
|
@@ -11,6 +11,7 @@ import type { Response as ExpressResponse } from 'express';
|
|
|
11
11
|
import { Connection, Model } from 'mongoose';
|
|
12
12
|
import { catchError, map, tap } from 'rxjs/operators';
|
|
13
13
|
import { UserContext } from '../features/user-context/user.context';
|
|
14
|
+
import { getErrorMessage } from '../utils/error';
|
|
14
15
|
import { SimpleAppDbRevertService } from './simple-app-db-revert.service';
|
|
15
16
|
@Injectable()
|
|
16
17
|
export class SimpleAppInterceptor implements NestInterceptor {
|
|
@@ -92,7 +93,7 @@ export class SimpleAppInterceptor implements NestInterceptor {
|
|
|
92
93
|
|
|
93
94
|
const responseBody = {
|
|
94
95
|
// eslint-disable-next-line
|
|
95
|
-
message: err.message,
|
|
96
|
+
message: getErrorMessage(err).message ?? err.message,
|
|
96
97
|
timestamp: new Date().toISOString(),
|
|
97
98
|
path: url,
|
|
98
99
|
// eslint-disable-next-line
|
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
export const camelToKebab = (value) => value.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
1
|
+
export const camelToKebab = (value: string) => value.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
3
|
+
export const isValidEmail = (value: unknown): value is string => typeof value === 'string' && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
4
|
+
|
|
5
|
+
export const nameFromEmail = (email: string): string => {
|
|
6
|
+
return email.split('@')[0];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const escapeRegExp = (value: string): string => value.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
|
|
10
|
+
|
|
11
|
+
export function paddedUniqueCodeGenerator(usedCodes: Set<string>, prefix = 'LVL', padSize = 3) {
|
|
12
|
+
let index = 1;
|
|
13
|
+
|
|
14
|
+
const format = (n: number) => `${prefix}_${String(n).padStart(padSize, '0')}`;
|
|
15
|
+
|
|
16
|
+
return () => {
|
|
17
|
+
let code: string;
|
|
18
|
+
|
|
19
|
+
do {
|
|
20
|
+
code = format(index++);
|
|
21
|
+
} while (usedCodes.has(code));
|
|
22
|
+
|
|
23
|
+
usedCodes.add(code);
|
|
24
|
+
|
|
25
|
+
return code;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -4,42 +4,53 @@
|
|
|
4
4
|
* last change 2024-02-24
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
-
import {getAllDocuments} from
|
|
8
|
-
import { FormCrudEvent,SimpleAppDocumentType } from
|
|
9
|
-
export const getDocument = (docname:SimpleAppDocumentType) =>{
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { getAllDocuments } from "~/simpleapp/generate/commons/documents";
|
|
8
|
+
import { FormCrudEvent, SimpleAppDocumentType } from "~/types";
|
|
9
|
+
export const getDocument = (docname: SimpleAppDocumentType | string) => {
|
|
10
|
+
const normalizedDocName = `${docname ?? ""}`.trim().toLowerCase();
|
|
11
|
+
if (!normalizedDocName) return undefined;
|
|
12
|
+
|
|
13
|
+
return getAllDocuments().find((item) => item.docName?.toLowerCase() == normalizedDocName); //?.docClass
|
|
14
|
+
};
|
|
12
15
|
|
|
13
16
|
// (appuser: UserContext, filter: any) => Promise<void>;
|
|
14
|
-
export const onScreenAddDocument = <T>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
17
|
+
export const onScreenAddDocument = <T>(
|
|
18
|
+
docname: SimpleAppDocumentType,
|
|
19
|
+
paras?: T,
|
|
20
|
+
after?: (eventType: FormCrudEvent, data: T, visible: Ref<boolean>) => Promise<void>,
|
|
21
|
+
) => {
|
|
22
|
+
useNuxtApp().$event("ViewRecord", {
|
|
23
|
+
documentName: docname,
|
|
24
|
+
eventId: randomUUID(),
|
|
25
|
+
_id: "new",
|
|
26
|
+
paras: paras,
|
|
27
|
+
document: getDocument(docname)?.docClass,
|
|
28
|
+
viewer: getDocument(docname)?.viewer,
|
|
29
|
+
after: (eventType: FormCrudEvent, data: any, visible: Ref<boolean>) => {
|
|
30
|
+
//do nothing
|
|
31
|
+
if (after) after(eventType, data as T, visible);
|
|
32
|
+
},
|
|
33
|
+
label: t(docname),
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const onScreenEditDocument = <T>(
|
|
38
|
+
docname: SimpleAppDocumentType,
|
|
39
|
+
_id: string,
|
|
40
|
+
after?: (eventType: FormCrudEvent, data: T, visible: Ref<boolean>) => Promise<void>,
|
|
41
|
+
autoclose: number = 1,
|
|
42
|
+
) => {
|
|
43
|
+
useNuxtApp().$event("ViewRecord", {
|
|
44
|
+
documentName: docname,
|
|
45
|
+
eventId: randomUUID(),
|
|
46
|
+
_id: _id,
|
|
47
|
+
autoclose: autoclose,
|
|
48
|
+
document: getDocument(docname)?.docClass,
|
|
49
|
+
viewer: getDocument(docname)?.viewer,
|
|
50
|
+
after: async (eventType: FormCrudEvent, data: any, visible: Ref<boolean>) => {
|
|
51
|
+
//do nothing
|
|
52
|
+
if (after) after(eventType, data as T, visible);
|
|
53
|
+
},
|
|
54
|
+
label: t(docname),
|
|
55
|
+
});
|
|
56
|
+
};
|
|
@@ -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,
|
package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppPageIframe.vue.eta
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
)
|
|
12
12
|
"
|
|
13
13
|
:title="pageInfo.title || t('miniAppLang.content')"
|
|
14
|
-
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-modals"
|
|
14
|
+
sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation allow-modals allow-downloads"
|
|
15
15
|
allow="clipboard-write"
|
|
16
16
|
referrerpolicy="origin"
|
|
17
17
|
loading="lazy"
|