MCPcopy
hub / github.com/thx/rap2-delos / moveInterface

Method moveInterface

src/service/repository.ts:99–157  ·  view source on GitHub ↗
(
    op: MoveOp,
    itfId: number,
    destRepoId: number,
    destModuleId: number,
    nameSuffix = '副本'
  )

Source from the content-addressed store, hash-verified

97 }
98
99 public static async moveInterface(
100 op: MoveOp,
101 itfId: number,
102 destRepoId: number,
103 destModuleId: number,
104 nameSuffix = '副本'
105 ) {
106 const itf = await Interface.findByPk(itfId)
107 const fromRepoId = itf.repositoryId
108 if (op === MoveOp.MOVE) {
109 itf.moduleId = destModuleId
110 itf.repositoryId = destRepoId
111 await Property.update(
112 {
113 moduleId: destModuleId,
114 repositoryId: destRepoId,
115 },
116 {
117 where: {
118 interfaceId: itf.id,
119 },
120 },
121 )
122 await itf.save()
123 } else if (op === MoveOp.COPY) {
124 const { id, name, ...otherProps } = itf.toJSON() as Interface
125 const newItf = await Interface.create({
126 name: name + nameSuffix,
127 ...otherProps,
128 repositoryId: destRepoId,
129 moduleId: destModuleId,
130 })
131
132 const properties = await Property.findAll({
133 where: {
134 interfaceId: itf.id,
135 },
136 order: [['parentId', 'asc']],
137 })
138 // 解决parentId丢失的问题
139 let idMap: any = {}
140 for (const property of properties) {
141 const { id, parentId, ...props } = property.toJSON() as Property
142 const newParentId = idMap[parentId + ''] ? idMap[parentId + ''] : -1
143 const newProperty = await Property.create({
144 ...props,
145 interfaceId: newItf.id,
146 parentId: newParentId,
147 repositoryId: destRepoId,
148 moduleId: destModuleId,
149 })
150 idMap[id + ''] = newProperty.id
151 }
152 }
153 await Promise.all([
154 RedisService.delCache(CACHE_KEY.REPOSITORY_GET, fromRepoId),
155 RedisService.delCache(CACHE_KEY.REPOSITORY_GET, destRepoId),
156 ])

Callers 2

moveModuleMethod · 0.80
repository.tsFile · 0.80

Calls 1

delCacheMethod · 0.80

Tested by

no test coverage detected