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

Method moveModule

src/service/repository.ts:50–97  ·  view source on GitHub ↗
(op: MoveOp, modId: number, destRepoId: number, nameSuffix = '副本')

Source from the content-addressed store, hash-verified

48 }
49
50 public static async moveModule(op: MoveOp, modId: number, destRepoId: number, nameSuffix = '副本') {
51 const mod = await Module.findByPk(modId)
52 const fromRepoId = mod.repositoryId
53 if (op === MoveOp.MOVE) {
54 mod.repositoryId = destRepoId
55 await mod.save()
56 await Interface.update(
57 {
58 repositoryId: destRepoId,
59 },
60 {
61 where: {
62 moduleId: modId,
63 },
64 },
65 )
66 await Property.update(
67 {
68 repositoryId: destRepoId,
69 },
70 {
71 where: {
72 moduleId: modId,
73 },
74 },
75 )
76 } else if (op === MoveOp.COPY) {
77 const { id, name, ...otherProps } = mod.toJSON() as Module
78 const interfaces = await Interface.findAll({
79 where: {
80 moduleId: modId,
81 },
82 })
83 const newMod = await Module.create({
84 name: mod.name + nameSuffix,
85 ...otherProps,
86 repositoryId: destRepoId,
87 })
88 const promises = interfaces.map(itf =>
89 RepositoryService.moveInterface(MoveOp.COPY, itf.id, destRepoId, newMod.id, ''),
90 )
91 await Promise.all(promises)
92 }
93 await Promise.all([
94 RedisService.delCache(CACHE_KEY.REPOSITORY_GET, fromRepoId),
95 RedisService.delCache(CACHE_KEY.REPOSITORY_GET, destRepoId),
96 ])
97 }
98
99 public static async moveInterface(
100 op: MoveOp,

Callers 1

repository.tsFile · 0.80

Calls 2

moveInterfaceMethod · 0.80
delCacheMethod · 0.80

Tested by

no test coverage detected