vona-module-test-vona 5.0.43 → 5.0.44
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/dist/.metadata/index.d.ts +32 -0
- package/dist/controller/captcha.d.ts +8 -0
- package/dist/dto/signin.d.ts +7 -0
- package/dist/index.js +589 -432
- package/dist/service/category.d.ts +1 -0
- package/dist/service/post.d.ts +24 -10
- package/dist/service/product.d.ts +3 -0
- package/package.json +1 -1
- package/src/.metadata/index.ts +43 -0
- package/src/controller/captcha.ts +18 -0
- package/src/dto/signin.ts +14 -0
- package/src/service/category.ts +88 -0
- package/src/service/order.ts +14 -10
- package/src/service/post.ts +53 -14
- package/src/service/product.ts +6 -0
- package/src/service/user.ts +15 -8
- package/test/captcha.test.ts +80 -0
package/dist/service/post.d.ts
CHANGED
|
@@ -1,32 +1,47 @@
|
|
|
1
1
|
import type { TableIdentity } from 'table-identity';
|
|
2
2
|
import { BeanBase } from 'vona';
|
|
3
|
+
import { ModelPost } from '../model/post.ts';
|
|
3
4
|
export declare class ServicePost extends BeanBase {
|
|
5
|
+
group(): Promise<({
|
|
6
|
+
userId: TableIdentity;
|
|
7
|
+
} & import("vona-module-a-orm").TypeRecordAggrsValuesToObject<import("vona-module-a-orm").TypeRecordAggrsValues<{
|
|
8
|
+
count: "count_all";
|
|
9
|
+
sum: "sum_stars";
|
|
10
|
+
}>>)[]>;
|
|
11
|
+
aggregate(): Promise<import("vona-module-a-orm").TypeRecordAggrsValuesToObject<import("vona-module-a-orm").TypeRecordAggrsValues<{
|
|
12
|
+
count: "count_all" | "count_stars";
|
|
13
|
+
sum: "sum_stars";
|
|
14
|
+
avg: "avg_stars";
|
|
15
|
+
min: "min_stars";
|
|
16
|
+
max: "max_stars";
|
|
17
|
+
}>>>;
|
|
18
|
+
count(): Promise<BigNumber | undefined>;
|
|
4
19
|
relationBelongsTo(): Promise<void>;
|
|
5
20
|
relationHasOne(): Promise<void>;
|
|
6
21
|
transaction(): Promise<void>;
|
|
7
22
|
transactionManually(): Promise<void>;
|
|
8
|
-
create(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost,
|
|
9
|
-
createBulk(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost,
|
|
10
|
-
update(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost,
|
|
11
|
-
update2(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost,
|
|
23
|
+
create(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost, ModelPost, import("vona-module-a-orm").IModelInsertOptions<import("vona-module-test-vona").EntityPost, ModelPost>, true>>;
|
|
24
|
+
createBulk(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost, ModelPost, import("vona-module-a-orm").IModelInsertOptions<import("vona-module-test-vona").EntityPost, ModelPost>, true>[]>;
|
|
25
|
+
update(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost, ModelPost, import("vona-module-a-orm").IModelUpdateOptions<import("vona-module-test-vona").EntityPost, ModelPost>>>;
|
|
26
|
+
update2(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost, ModelPost, {
|
|
12
27
|
where: {
|
|
13
28
|
title: {
|
|
14
29
|
_startsWith_: string;
|
|
15
30
|
};
|
|
16
31
|
};
|
|
17
32
|
}>>;
|
|
18
|
-
updateBulk(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost,
|
|
33
|
+
updateBulk(): Promise<import("vona-module-a-orm").TypeModelMutateRelationData<import("vona-module-test-vona").EntityPost, ModelPost, import("vona-module-a-orm").IModelUpdateOptions<import("vona-module-test-vona").EntityPost, ModelPost>>[]>;
|
|
19
34
|
delete(): Promise<void>;
|
|
20
35
|
delete2(): Promise<void>;
|
|
21
36
|
deleteBulk(): Promise<void>;
|
|
22
37
|
mutate(): Promise<void>;
|
|
23
38
|
mutateBulk(): Promise<void>;
|
|
24
|
-
select(): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost,
|
|
39
|
+
select(): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost, ModelPost, {
|
|
25
40
|
where: {
|
|
26
41
|
stars: "_skip_";
|
|
27
42
|
};
|
|
28
43
|
}, undefined, 50>[]>;
|
|
29
|
-
select2(): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost,
|
|
44
|
+
select2(): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost, ModelPost, {
|
|
30
45
|
columns: ("id" | "title" | "userId")[];
|
|
31
46
|
where: {
|
|
32
47
|
id: {
|
|
@@ -39,7 +54,6 @@ export declare class ServicePost extends BeanBase {
|
|
|
39
54
|
limit: number;
|
|
40
55
|
orders: ["createdAt", "desc"][];
|
|
41
56
|
}, undefined, 50>[]>;
|
|
42
|
-
get(id: TableIdentity): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost,
|
|
43
|
-
mget(ids: TableIdentity[]): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost,
|
|
44
|
-
count(): Promise<BigNumber | undefined>;
|
|
57
|
+
get(id: TableIdentity): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost, ModelPost, import("vona-module-a-orm").IModelGetOptions<import("vona-module-test-vona").EntityPost, ModelPost>, undefined, 50> | undefined>;
|
|
58
|
+
mget(ids: TableIdentity[]): Promise<import("vona-module-a-orm").TypeModelRelationResult_Normal<import("vona-module-test-vona").EntityPost, ModelPost, import("vona-module-a-orm").IModelGetOptions<import("vona-module-test-vona").EntityPost, ModelPost>, undefined, 50>[]>;
|
|
45
59
|
}
|
package/package.json
CHANGED
package/src/.metadata/index.ts
CHANGED
|
@@ -821,6 +821,7 @@ export * from '../service/caching.ts';
|
|
|
821
821
|
export * from '../service/category.ts';
|
|
822
822
|
export * from '../service/order.ts';
|
|
823
823
|
export * from '../service/post.ts';
|
|
824
|
+
export * from '../service/product.ts';
|
|
824
825
|
export * from '../service/test.ts';
|
|
825
826
|
export * from '../service/testApp.ts';
|
|
826
827
|
export * from '../service/testClass.ts';
|
|
@@ -837,6 +838,7 @@ declare module 'vona-module-a-bean' {
|
|
|
837
838
|
'test-vona:category': never;
|
|
838
839
|
'test-vona:order': never;
|
|
839
840
|
'test-vona:post': never;
|
|
841
|
+
'test-vona:product': never;
|
|
840
842
|
'test-vona:test': never;
|
|
841
843
|
'test-vona:testApp': never;
|
|
842
844
|
'test-vona:testClass': never;
|
|
@@ -899,6 +901,16 @@ declare module 'vona-module-test-vona' {
|
|
|
899
901
|
get $onionName(): 'test-vona:post';
|
|
900
902
|
}
|
|
901
903
|
|
|
904
|
+
export interface ServiceProduct {
|
|
905
|
+
/** @internal */
|
|
906
|
+
get scope(): ScopeModuleTestVona;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
export interface ServiceProduct {
|
|
910
|
+
get $beanFullName(): 'test-vona.service.product';
|
|
911
|
+
get $onionName(): 'test-vona:product';
|
|
912
|
+
}
|
|
913
|
+
|
|
902
914
|
export interface ServiceTest {
|
|
903
915
|
/** @internal */
|
|
904
916
|
get scope(): ScopeModuleTestVona;
|
|
@@ -966,6 +978,7 @@ import type { ServiceCaching } from '../service/caching.ts';
|
|
|
966
978
|
import type { ServiceCategory } from '../service/category.ts';
|
|
967
979
|
import type { ServiceOrder } from '../service/order.ts';
|
|
968
980
|
import type { ServicePost } from '../service/post.ts';
|
|
981
|
+
import type { ServiceProduct } from '../service/product.ts';
|
|
969
982
|
import type { ServiceTest } from '../service/test.ts';
|
|
970
983
|
import type { ServiceTestApp } from '../service/testApp.ts';
|
|
971
984
|
import type { ServiceTestClass } from '../service/testClass.ts';
|
|
@@ -978,6 +991,7 @@ export interface IModuleService {
|
|
|
978
991
|
'category': ServiceCategory;
|
|
979
992
|
'order': ServiceOrder;
|
|
980
993
|
'post': ServicePost;
|
|
994
|
+
'product': ServiceProduct;
|
|
981
995
|
'test': ServiceTest;
|
|
982
996
|
'testApp': ServiceTestApp;
|
|
983
997
|
'testClass': ServiceTestClass;
|
|
@@ -996,6 +1010,7 @@ declare module 'vona' {
|
|
|
996
1010
|
'test-vona.service.category': ServiceCategory;
|
|
997
1011
|
'test-vona.service.order': ServiceOrder;
|
|
998
1012
|
'test-vona.service.post': ServicePost;
|
|
1013
|
+
'test-vona.service.product': ServiceProduct;
|
|
999
1014
|
'test-vona.service.test': ServiceTest;
|
|
1000
1015
|
'test-vona.service.testApp': ServiceTestApp;
|
|
1001
1016
|
'test-vona.service.testClass': ServiceTestClass;
|
|
@@ -1305,6 +1320,7 @@ export * from '../dto/orderUpdate.ts';
|
|
|
1305
1320
|
export * from '../dto/postCreate.ts';
|
|
1306
1321
|
export * from '../dto/profile.ts';
|
|
1307
1322
|
export * from '../dto/roleLazy.ts';
|
|
1323
|
+
export * from '../dto/signin.ts';
|
|
1308
1324
|
export * from '../dto/user.ts';
|
|
1309
1325
|
export * from '../dto/userCreate.ts';
|
|
1310
1326
|
export * from '../dto/userLazy.ts';
|
|
@@ -1316,6 +1332,7 @@ import type { IDtoOptionsOrderUpdate } from '../dto/orderUpdate.ts';
|
|
|
1316
1332
|
import type { IDtoOptionsPostCreate } from '../dto/postCreate.ts';
|
|
1317
1333
|
import type { IDtoOptionsProfile } from '../dto/profile.ts';
|
|
1318
1334
|
import type { IDtoOptionsRoleLazy } from '../dto/roleLazy.ts';
|
|
1335
|
+
import type { IDtoOptionsSignin } from '../dto/signin.ts';
|
|
1319
1336
|
import type { IDtoOptionsUser } from '../dto/user.ts';
|
|
1320
1337
|
import type { IDtoOptionsUserCreate } from '../dto/userCreate.ts';
|
|
1321
1338
|
import type { IDtoOptionsUserLazy } from '../dto/userLazy.ts';
|
|
@@ -1331,6 +1348,7 @@ declare module 'vona-module-a-web' {
|
|
|
1331
1348
|
'test-vona:postCreate': IDtoOptionsPostCreate;
|
|
1332
1349
|
'test-vona:profile': IDtoOptionsProfile;
|
|
1333
1350
|
'test-vona:roleLazy': IDtoOptionsRoleLazy;
|
|
1351
|
+
'test-vona:signin': IDtoOptionsSignin;
|
|
1334
1352
|
'test-vona:user': IDtoOptionsUser;
|
|
1335
1353
|
'test-vona:userCreate': IDtoOptionsUserCreate;
|
|
1336
1354
|
'test-vona:userLazy': IDtoOptionsUserLazy;
|
|
@@ -1351,6 +1369,7 @@ import type { DtoOrderUpdate } from '../dto/orderUpdate.ts';
|
|
|
1351
1369
|
import type { DtoPostCreate } from '../dto/postCreate.ts';
|
|
1352
1370
|
import type { DtoProfile } from '../dto/profile.ts';
|
|
1353
1371
|
import type { DtoRoleLazy } from '../dto/roleLazy.ts';
|
|
1372
|
+
import type { DtoSignin } from '../dto/signin.ts';
|
|
1354
1373
|
import type { DtoUser } from '../dto/user.ts';
|
|
1355
1374
|
import type { DtoUserCreate } from '../dto/userCreate.ts';
|
|
1356
1375
|
import type { DtoUserLazy } from '../dto/userLazy.ts';
|
|
@@ -1385,6 +1404,10 @@ declare module 'vona-module-test-vona' {
|
|
|
1385
1404
|
fields?: TypeEntityOptionsFields<DtoRoleLazy, IDtoOptionsRoleLazy[TypeSymbolKeyFieldsMore]>;
|
|
1386
1405
|
}
|
|
1387
1406
|
|
|
1407
|
+
export interface IDtoOptionsSignin {
|
|
1408
|
+
fields?: TypeEntityOptionsFields<DtoSignin, IDtoOptionsSignin[TypeSymbolKeyFieldsMore]>;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1388
1411
|
export interface IDtoOptionsUser {
|
|
1389
1412
|
fields?: TypeEntityOptionsFields<DtoUser, IDtoOptionsUser[TypeSymbolKeyFieldsMore]>;
|
|
1390
1413
|
}
|
|
@@ -1406,6 +1429,7 @@ declare module 'vona-module-test-vona' {
|
|
|
1406
1429
|
export * from '../controller/bean.ts';
|
|
1407
1430
|
export * from '../controller/cacheMem.ts';
|
|
1408
1431
|
export * from '../controller/cacheRedis.ts';
|
|
1432
|
+
export * from '../controller/captcha.ts';
|
|
1409
1433
|
export * from '../controller/dtoTest.ts';
|
|
1410
1434
|
export * from '../controller/guardPassport.ts';
|
|
1411
1435
|
export * from '../controller/onion.ts';
|
|
@@ -1419,6 +1443,7 @@ export * from '../controller/upload.ts';
|
|
|
1419
1443
|
import type { IControllerOptionsBean } from '../controller/bean.ts';
|
|
1420
1444
|
import type { IControllerOptionsCacheMem } from '../controller/cacheMem.ts';
|
|
1421
1445
|
import type { IControllerOptionsCacheRedis } from '../controller/cacheRedis.ts';
|
|
1446
|
+
import type { IControllerOptionsCaptcha } from '../controller/captcha.ts';
|
|
1422
1447
|
import type { IControllerOptionsDtoTest } from '../controller/dtoTest.ts';
|
|
1423
1448
|
import type { IControllerOptionsGuardPassport } from '../controller/guardPassport.ts';
|
|
1424
1449
|
import type { IControllerOptionsOnion } from '../controller/onion.ts';
|
|
@@ -1436,6 +1461,7 @@ declare module 'vona-module-a-web' {
|
|
|
1436
1461
|
'test-vona:bean': IControllerOptionsBean;
|
|
1437
1462
|
'test-vona:cacheMem': IControllerOptionsCacheMem;
|
|
1438
1463
|
'test-vona:cacheRedis': IControllerOptionsCacheRedis;
|
|
1464
|
+
'test-vona:captcha': IControllerOptionsCaptcha;
|
|
1439
1465
|
'test-vona:dtoTest': IControllerOptionsDtoTest;
|
|
1440
1466
|
'test-vona:guardPassport': IControllerOptionsGuardPassport;
|
|
1441
1467
|
'test-vona:onion': IControllerOptionsOnion;
|
|
@@ -1482,6 +1508,16 @@ declare module 'vona-module-test-vona' {
|
|
|
1482
1508
|
get $onionName(): 'test-vona:cacheRedis';
|
|
1483
1509
|
}
|
|
1484
1510
|
|
|
1511
|
+
export interface ControllerCaptcha {
|
|
1512
|
+
/** @internal */
|
|
1513
|
+
get scope(): ScopeModuleTestVona;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
export interface ControllerCaptcha {
|
|
1517
|
+
get $beanFullName(): 'test-vona.controller.captcha';
|
|
1518
|
+
get $onionName(): 'test-vona:captcha';
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1485
1521
|
export interface ControllerDtoTest {
|
|
1486
1522
|
/** @internal */
|
|
1487
1523
|
get scope(): ScopeModuleTestVona;
|
|
@@ -1591,6 +1627,8 @@ import type { ControllerCacheMem } from '../controller/cacheMem.ts';
|
|
|
1591
1627
|
// @ts-ignore ignore
|
|
1592
1628
|
import type { ControllerCacheRedis } from '../controller/cacheRedis.ts';
|
|
1593
1629
|
// @ts-ignore ignore
|
|
1630
|
+
import type { ControllerCaptcha } from '../controller/captcha.ts';
|
|
1631
|
+
// @ts-ignore ignore
|
|
1594
1632
|
import type { ControllerDtoTest } from '../controller/dtoTest.ts';
|
|
1595
1633
|
// @ts-ignore ignore
|
|
1596
1634
|
import type { ControllerGuardPassport } from '../controller/guardPassport.ts';
|
|
@@ -1624,6 +1662,10 @@ declare module 'vona-module-test-vona' {
|
|
|
1624
1662
|
actions?: TypeControllerOptionsActions<ControllerCacheRedis>;
|
|
1625
1663
|
}
|
|
1626
1664
|
|
|
1665
|
+
export interface IControllerOptionsCaptcha {
|
|
1666
|
+
actions?: TypeControllerOptionsActions<ControllerCaptcha>;
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1627
1669
|
export interface IControllerOptionsDtoTest {
|
|
1628
1670
|
actions?: TypeControllerOptionsActions<ControllerDtoTest>;
|
|
1629
1671
|
}
|
|
@@ -1688,6 +1730,7 @@ declare module 'vona-module-a-web' {
|
|
|
1688
1730
|
export interface IApiPathPostRecord{
|
|
1689
1731
|
'/test/vona/cacheMem': undefined;
|
|
1690
1732
|
'/test/vona/cacheRedis': undefined;
|
|
1733
|
+
'/test/vona/captcha/signin': undefined;
|
|
1691
1734
|
'/test/vona/dtoTest/createUser': undefined;
|
|
1692
1735
|
'//echo': undefined;
|
|
1693
1736
|
'/test/vona/onion/echo2/:userId/:userName': undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IDecoratorControllerOptions } from 'vona-module-a-web';
|
|
2
|
+
import { BeanBase } from 'vona';
|
|
3
|
+
import { Aspect } from 'vona-module-a-aspect';
|
|
4
|
+
import { Arg } from 'vona-module-a-openapi';
|
|
5
|
+
import { Passport } from 'vona-module-a-user';
|
|
6
|
+
import { Controller, Web } from 'vona-module-a-web';
|
|
7
|
+
import { DtoSignin } from '../dto/signin.ts';
|
|
8
|
+
|
|
9
|
+
export interface IControllerOptionsCaptcha extends IDecoratorControllerOptions {}
|
|
10
|
+
|
|
11
|
+
@Controller<IControllerOptionsCaptcha>({ path: 'captcha', meta: { mode: ['test', 'dev'] } })
|
|
12
|
+
export class ControllerCaptcha extends BeanBase {
|
|
13
|
+
@Web.post('signin')
|
|
14
|
+
@Passport.public()
|
|
15
|
+
@Aspect.middleware('a-captcha:captcha', { scene: 'a-captchasimple:simple' })
|
|
16
|
+
async signin(@Arg.body() _user: DtoSignin) {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDecoratorDtoOptions } from 'vona-module-a-web';
|
|
2
|
+
import { Api, v } from 'vona-module-a-openapi';
|
|
3
|
+
import { Dto } from 'vona-module-a-web';
|
|
4
|
+
|
|
5
|
+
export interface IDtoOptionsSignin extends IDecoratorDtoOptions {}
|
|
6
|
+
|
|
7
|
+
@Dto<IDtoOptionsSignin>()
|
|
8
|
+
export class DtoSignin {
|
|
9
|
+
@Api.field()
|
|
10
|
+
username: string;
|
|
11
|
+
|
|
12
|
+
@Api.field(v.min(3))
|
|
13
|
+
password: string;
|
|
14
|
+
}
|
package/src/service/category.ts
CHANGED
|
@@ -1,9 +1,97 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { BeanBase } from 'vona';
|
|
3
3
|
import { Service } from 'vona-module-a-bean';
|
|
4
|
+
import { $relationDynamic } from 'vona-module-a-orm';
|
|
5
|
+
import { ModelCategory } from '../model/category.ts';
|
|
4
6
|
|
|
5
7
|
@Service()
|
|
6
8
|
export class ServiceCategory extends BeanBase {
|
|
9
|
+
async categoryTreeDynamic() {
|
|
10
|
+
// create
|
|
11
|
+
const treeCreate = await this.scope.model.category.insert(
|
|
12
|
+
{
|
|
13
|
+
name: 'Category-1',
|
|
14
|
+
children2: [
|
|
15
|
+
{
|
|
16
|
+
name: 'Category-1-1',
|
|
17
|
+
children2: [
|
|
18
|
+
{ name: 'Category-1-1-1' },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'Category-1-2',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
with: {
|
|
28
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent', {
|
|
29
|
+
with: {
|
|
30
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent', {
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
// get
|
|
38
|
+
const tree = await this.scope.model.category.get(
|
|
39
|
+
{
|
|
40
|
+
id: treeCreate.id,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
with: {
|
|
44
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent', {
|
|
45
|
+
columns: ['id', 'name'],
|
|
46
|
+
with: {
|
|
47
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent', {
|
|
48
|
+
columns: ['id', 'name'],
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
assert.equal(tree?.children2.length, 2);
|
|
56
|
+
assert.equal(tree?.children2[0].children2.length, 1);
|
|
57
|
+
// update
|
|
58
|
+
await this.scope.model.category.update(
|
|
59
|
+
{
|
|
60
|
+
id: treeCreate.id,
|
|
61
|
+
name: 'Category-1-Update',
|
|
62
|
+
children2: [
|
|
63
|
+
// create
|
|
64
|
+
{ name: 'Category-1-3' },
|
|
65
|
+
// update
|
|
66
|
+
{ id: treeCreate.children2?.[0].id, name: 'Category-1-1-Update' },
|
|
67
|
+
// delete
|
|
68
|
+
{ id: treeCreate.children2?.[1].id, deleted: true },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
with: {
|
|
73
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent'),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
// delete
|
|
78
|
+
await this.scope.model.category.delete(
|
|
79
|
+
{
|
|
80
|
+
id: treeCreate.id,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
with: {
|
|
84
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent', {
|
|
85
|
+
with: {
|
|
86
|
+
children2: $relationDynamic.hasMany(() => ModelCategory, 'categoryIdParent', {
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
7
95
|
async categoryTreeReverse() {
|
|
8
96
|
// create
|
|
9
97
|
const treeCreate = await this.scope.model.category.insert({
|
package/src/service/order.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BeanBase } from 'vona';
|
|
2
2
|
import { Service } from 'vona-module-a-bean';
|
|
3
|
+
import { $relationDynamic } from 'vona-module-a-orm';
|
|
4
|
+
import { ModelProduct } from '../model/product.ts';
|
|
3
5
|
|
|
4
6
|
@Service()
|
|
5
7
|
export class ServiceOrder extends BeanBase {
|
|
@@ -8,14 +10,14 @@ export class ServiceOrder extends BeanBase {
|
|
|
8
10
|
const orderCreate = await this.scope.model.order.insert(
|
|
9
11
|
{
|
|
10
12
|
orderNo: 'Order001',
|
|
11
|
-
|
|
13
|
+
products2: [
|
|
12
14
|
{ name: 'Apple' },
|
|
13
15
|
{ name: 'Pear' },
|
|
14
16
|
],
|
|
15
17
|
},
|
|
16
18
|
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
with: {
|
|
20
|
+
products2: $relationDynamic.hasMany(() => ModelProduct, 'orderId'),
|
|
19
21
|
},
|
|
20
22
|
},
|
|
21
23
|
);
|
|
@@ -25,8 +27,10 @@ export class ServiceOrder extends BeanBase {
|
|
|
25
27
|
id: orderCreate.id,
|
|
26
28
|
},
|
|
27
29
|
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
with: {
|
|
31
|
+
products2: $relationDynamic.hasMany(() => ModelProduct, 'orderId', {
|
|
32
|
+
columns: ['id', 'name', 'price', 'quantity', 'amount'],
|
|
33
|
+
}),
|
|
30
34
|
},
|
|
31
35
|
},
|
|
32
36
|
);
|
|
@@ -35,7 +39,7 @@ export class ServiceOrder extends BeanBase {
|
|
|
35
39
|
{
|
|
36
40
|
id: orderCreate.id,
|
|
37
41
|
orderNo: 'Order001-Update',
|
|
38
|
-
|
|
42
|
+
products2: [
|
|
39
43
|
// create product: Peach
|
|
40
44
|
{ name: 'Peach' },
|
|
41
45
|
// update product: Apple
|
|
@@ -45,8 +49,8 @@ export class ServiceOrder extends BeanBase {
|
|
|
45
49
|
],
|
|
46
50
|
},
|
|
47
51
|
{
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
with: {
|
|
53
|
+
products2: $relationDynamic.hasMany(() => ModelProduct, 'orderId'),
|
|
50
54
|
},
|
|
51
55
|
},
|
|
52
56
|
);
|
|
@@ -56,8 +60,8 @@ export class ServiceOrder extends BeanBase {
|
|
|
56
60
|
id: orderCreate.id,
|
|
57
61
|
},
|
|
58
62
|
{
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
with: {
|
|
64
|
+
products2: $relationDynamic.hasMany(() => ModelProduct, 'orderId'),
|
|
61
65
|
},
|
|
62
66
|
},
|
|
63
67
|
);
|
package/src/service/post.ts
CHANGED
|
@@ -1,14 +1,47 @@
|
|
|
1
1
|
import type { TableIdentity } from 'table-identity';
|
|
2
2
|
import { BeanBase } from 'vona';
|
|
3
3
|
import { Service } from 'vona-module-a-bean';
|
|
4
|
-
import { Database } from 'vona-module-a-orm';
|
|
4
|
+
import { $relationDynamic, Database } from 'vona-module-a-orm';
|
|
5
|
+
import { ModelPost } from '../model/post.ts';
|
|
6
|
+
import { ModelPostContent } from '../model/postContent.ts';
|
|
5
7
|
|
|
6
8
|
@Service()
|
|
7
9
|
export class ServicePost extends BeanBase {
|
|
10
|
+
async group() {
|
|
11
|
+
const result = await this.scope.model.post.group({
|
|
12
|
+
groups: 'userId',
|
|
13
|
+
aggrs: {
|
|
14
|
+
count: '*',
|
|
15
|
+
sum: 'stars',
|
|
16
|
+
},
|
|
17
|
+
orders: [['count_all', 'desc']],
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async aggregate() {
|
|
23
|
+
const result = await this.scope.model.post.aggregate({
|
|
24
|
+
aggrs: {
|
|
25
|
+
count: ['*', 'stars'],
|
|
26
|
+
sum: 'stars',
|
|
27
|
+
avg: 'stars',
|
|
28
|
+
min: 'stars',
|
|
29
|
+
max: 'stars',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async count() {
|
|
36
|
+
return await this.scope.model.post.count();
|
|
37
|
+
}
|
|
38
|
+
|
|
8
39
|
async relationBelongsTo() {
|
|
9
40
|
const postContent = await this.scope.model.postContent.select({
|
|
10
|
-
|
|
11
|
-
post:
|
|
41
|
+
with: {
|
|
42
|
+
post: $relationDynamic.belongsTo(() => ModelPostContent, () => ModelPost, 'postId', {
|
|
43
|
+
columns: ['id', 'title'],
|
|
44
|
+
}),
|
|
12
45
|
},
|
|
13
46
|
});
|
|
14
47
|
console.log(postContent[0]?.post?.title);
|
|
@@ -24,8 +57,10 @@ export class ServicePost extends BeanBase {
|
|
|
24
57
|
},
|
|
25
58
|
},
|
|
26
59
|
{
|
|
27
|
-
|
|
28
|
-
postContent:
|
|
60
|
+
with: {
|
|
61
|
+
postContent: $relationDynamic.hasOne(() => ModelPostContent, 'postId', {
|
|
62
|
+
columns: ['id', 'content'],
|
|
63
|
+
}),
|
|
29
64
|
},
|
|
30
65
|
},
|
|
31
66
|
);
|
|
@@ -35,8 +70,10 @@ export class ServicePost extends BeanBase {
|
|
|
35
70
|
id: postCreate.id,
|
|
36
71
|
},
|
|
37
72
|
{
|
|
38
|
-
|
|
39
|
-
postContent:
|
|
73
|
+
with: {
|
|
74
|
+
postContent: $relationDynamic.hasOne(() => ModelPostContent, 'postId', {
|
|
75
|
+
columns: ['id', 'content'],
|
|
76
|
+
}),
|
|
40
77
|
},
|
|
41
78
|
},
|
|
42
79
|
);
|
|
@@ -50,8 +87,10 @@ export class ServicePost extends BeanBase {
|
|
|
50
87
|
},
|
|
51
88
|
},
|
|
52
89
|
{
|
|
53
|
-
|
|
54
|
-
postContent:
|
|
90
|
+
with: {
|
|
91
|
+
postContent: $relationDynamic.hasOne(() => ModelPostContent, 'postId', {
|
|
92
|
+
columns: ['id', 'content'],
|
|
93
|
+
}),
|
|
55
94
|
},
|
|
56
95
|
},
|
|
57
96
|
);
|
|
@@ -61,8 +100,8 @@ export class ServicePost extends BeanBase {
|
|
|
61
100
|
id: postCreate.id,
|
|
62
101
|
},
|
|
63
102
|
{
|
|
64
|
-
|
|
65
|
-
postContent:
|
|
103
|
+
with: {
|
|
104
|
+
postContent: $relationDynamic.hasOne(() => ModelPostContent, 'postId'),
|
|
66
105
|
},
|
|
67
106
|
},
|
|
68
107
|
);
|
|
@@ -213,7 +252,7 @@ export class ServicePost extends BeanBase {
|
|
|
213
252
|
return await this.scope.model.post.mget(ids);
|
|
214
253
|
}
|
|
215
254
|
|
|
216
|
-
async count() {
|
|
217
|
-
|
|
218
|
-
}
|
|
255
|
+
// async count() {
|
|
256
|
+
// return await this.scope.model.post.count();
|
|
257
|
+
// }
|
|
219
258
|
}
|
package/src/service/user.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { BeanBase } from 'vona';
|
|
2
2
|
import { Service } from 'vona-module-a-bean';
|
|
3
|
+
import { $relationDynamic } from 'vona-module-a-orm';
|
|
4
|
+
import { ModelRole } from '../model/role.ts';
|
|
5
|
+
import { ModelRoleUser } from '../model/roleUser.ts';
|
|
3
6
|
|
|
4
7
|
@Service()
|
|
5
8
|
export class ServiceUser extends BeanBase {
|
|
@@ -20,8 +23,8 @@ export class ServiceUser extends BeanBase {
|
|
|
20
23
|
}],
|
|
21
24
|
},
|
|
22
25
|
{
|
|
23
|
-
|
|
24
|
-
roles:
|
|
26
|
+
with: {
|
|
27
|
+
roles: $relationDynamic.belongsToMany(() => ModelRoleUser, () => ModelRole, 'userId', 'roleId'),
|
|
25
28
|
},
|
|
26
29
|
},
|
|
27
30
|
);
|
|
@@ -31,8 +34,10 @@ export class ServiceUser extends BeanBase {
|
|
|
31
34
|
id: userCreate.id,
|
|
32
35
|
},
|
|
33
36
|
{
|
|
34
|
-
|
|
35
|
-
roles:
|
|
37
|
+
with: {
|
|
38
|
+
roles: $relationDynamic.belongsToMany(() => ModelRoleUser, () => ModelRole, 'userId', 'roleId', {
|
|
39
|
+
columns: ['id', 'name'],
|
|
40
|
+
}),
|
|
36
41
|
},
|
|
37
42
|
},
|
|
38
43
|
);
|
|
@@ -48,8 +53,10 @@ export class ServiceUser extends BeanBase {
|
|
|
48
53
|
],
|
|
49
54
|
},
|
|
50
55
|
{
|
|
51
|
-
|
|
52
|
-
roles:
|
|
56
|
+
with: {
|
|
57
|
+
roles: $relationDynamic.belongsToMany(() => ModelRoleUser, () => ModelRole, 'userId', 'roleId', {
|
|
58
|
+
columns: ['id', 'name'],
|
|
59
|
+
}),
|
|
53
60
|
},
|
|
54
61
|
},
|
|
55
62
|
);
|
|
@@ -59,8 +66,8 @@ export class ServiceUser extends BeanBase {
|
|
|
59
66
|
id: userCreate.id,
|
|
60
67
|
},
|
|
61
68
|
{
|
|
62
|
-
|
|
63
|
-
roles:
|
|
69
|
+
with: {
|
|
70
|
+
roles: $relationDynamic.belongsToMany(() => ModelRoleUser, () => ModelRole, 'userId', 'roleId'),
|
|
64
71
|
},
|
|
65
72
|
},
|
|
66
73
|
);
|