1
- import { IPData , Prisma , ProtocolData , RouterTypeData , SwitchTypeData } from '@prisma/client' ;
1
+ import { Prisma , ProtocolData } from '@prisma/client' ;
2
2
import { Router } from 'src/domain/entity/router' ;
3
3
import { Switch } from 'src/domain/entity/switch' ;
4
4
import { IP } from 'src/domain/vo/ip' ;
@@ -23,30 +23,24 @@ export class RouterPrismaMapper {
23
23
return new Router ( routerType , routerId , networkSwitch ) ;
24
24
}
25
25
26
- public static toPrisma ( router : Router ) : Prisma . RouterDataCreateInput {
27
- const routerDataType = RouterTypeData [ RouterType [ router . type ] ] ;
26
+ public static toPrisma ( router : Router ) : Prisma . NetworkDataCreateArgs {
28
27
const routerDataId = router . routerId . toString ( ) ;
29
- const switchDataId = router . networkSwitch . id ;
30
- const switchTypeData = SwitchTypeData [ SwitchType [ router . networkSwitch . type ] ] ;
31
- const ipData : IPData = {
32
- address : router . networkSwitch . address . address ,
33
- protocol : ProtocolData [ Protocol [ router . networkSwitch . address . protocol ] ] ,
34
- } ;
35
28
36
- const networkDataList = this . _getNetworksFromDomain ( router . networkSwitch . getNetworks ( ) ) ;
29
+ const networks = router . networkSwitch . getNetworks ( ) . at ( - 1 ) ;
37
30
38
31
return {
39
- id : routerDataId ,
40
- type : routerDataType ,
41
- networkSwitch : {
42
- create : {
43
- id : switchDataId . toString ( ) ,
44
- type : switchTypeData ,
45
- ip : {
46
- create : ipData ,
32
+ data : {
33
+ switch : {
34
+ connect : {
35
+ routerId : routerDataId ,
47
36
} ,
48
- networks : {
49
- create : networkDataList ,
37
+ } ,
38
+ cidr : networks . cidr ,
39
+ name : networks . name ,
40
+ ip : {
41
+ create : {
42
+ address : networks . address . address ,
43
+ protocol : ProtocolData [ Protocol [ networks . address . protocol ] ] ,
50
44
} ,
51
45
} ,
52
46
} ,
@@ -56,17 +50,4 @@ export class RouterPrismaMapper {
56
50
private static _getNetworksFromData ( networkData : NetworkDataType [ ] ) : Network [ ] {
57
51
return networkData . map ( ( { ip : { address } , name, cidr } ) => new Network ( IP . fromAddress ( address ) , name , cidr ) ) ;
58
52
}
59
-
60
- private static _getNetworksFromDomain ( networks : Network [ ] ) : Prisma . NetworkDataCreateWithoutSwitchInput [ ] {
61
- return networks . map < Prisma . NetworkDataCreateWithoutSwitchInput > ( ( { cidr, address : { address, protocol } , name } ) => ( {
62
- cidr,
63
- name,
64
- ip : {
65
- create : {
66
- address,
67
- protocol : ProtocolData [ Protocol [ protocol ] ] ,
68
- } ,
69
- } ,
70
- } ) ) ;
71
- }
72
53
}
0 commit comments