({
ctx,
input,
}: InferProcedureOpts<typeof baseProcedureStep1>)
| 97 | } |
| 98 | |
| 99 | export async function moveStep1({ |
| 100 | ctx, |
| 101 | input, |
| 102 | }: InferProcedureOpts<typeof baseProcedureStep1>) { |
| 103 | return await ctx.dataAbstraction.transaction(async (dtrx) => { |
| 104 | // Assert user is subscribed |
| 105 | |
| 106 | await ctx.assertUserSubscribed({ userId: ctx.userId }); |
| 107 | |
| 108 | // Check sufficient permissions |
| 109 | |
| 110 | await ctx.assertSufficientGroupPermissions({ |
| 111 | userId: ctx.userId, |
| 112 | groupId: (ctx as Context).sourceGroupId, |
| 113 | permission: 'editGroupSettings', |
| 114 | }); |
| 115 | |
| 116 | if (input.groupCreation == null) { |
| 117 | await ctx.assertSufficientGroupPermissions({ |
| 118 | userId: ctx.userId, |
| 119 | groupId: input.destGroupId, |
| 120 | permission: 'editGroupPages', |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | // Check if page is main page of source group |
| 125 | |
| 126 | if ( |
| 127 | input.pageId === |
| 128 | (await ctx.dataAbstraction.hget( |
| 129 | 'group', |
| 130 | (ctx as Context).sourceGroupId, |
| 131 | 'main-page-id', |
| 132 | )) |
| 133 | ) { |
| 134 | throw new TRPCError({ |
| 135 | code: 'BAD_REQUEST', |
| 136 | message: |
| 137 | 'Cannot move main page of a group. Please set another page as main page first.', |
| 138 | }); |
| 139 | } |
| 140 | |
| 141 | // Create group if requested |
| 142 | |
| 143 | if (input.groupCreation != null) { |
| 144 | await createGroup({ |
| 145 | userId: ctx.userId, |
| 146 | |
| 147 | groupId: input.destGroupId, |
| 148 | groupMainPageId: input.pageId, |
| 149 | groupIsPersonal: false, |
| 150 | |
| 151 | ...input.groupCreation, |
| 152 | |
| 153 | dtrx, |
| 154 | }); |
| 155 | } |
| 156 |
nothing calls this directly
no test coverage detected