({
ctx,
input,
}: InferProcedureOpts<typeof baseProcedureStep2>)
| 192 | } |
| 193 | |
| 194 | export async function moveStep2({ |
| 195 | ctx, |
| 196 | input, |
| 197 | }: InferProcedureOpts<typeof baseProcedureStep2>) { |
| 198 | return await ctx.dataAbstraction.transaction(async (dtrx) => { |
| 199 | // Set page as main page of destination group |
| 200 | |
| 201 | if ((ctx as Context).setAsMainPage) { |
| 202 | const [destGroupOldMainPageId, destGroupMemberId] = |
| 203 | await ctx.dataAbstraction.mhget([ |
| 204 | hget('group', (ctx as Context).destGroupId, 'main-page-id'), |
| 205 | hget('group', (ctx as Context).destGroupId, 'user-id'), |
| 206 | ]); |
| 207 | |
| 208 | const oldLastParentId = await ctx.dataAbstraction.hget( |
| 209 | 'user-page', |
| 210 | `${ctx.userId}:${destGroupOldMainPageId}`, |
| 211 | 'last-parent-id', |
| 212 | ); |
| 213 | |
| 214 | // Replacing main page of personal group |
| 215 | // Update last parent IDs of relevant pages |
| 216 | |
| 217 | if ( |
| 218 | ctx.userId === destGroupMemberId && |
| 219 | (ctx as Context).pageId !== destGroupOldMainPageId |
| 220 | ) { |
| 221 | await ctx.dataAbstraction.patch( |
| 222 | 'user-page', |
| 223 | `${ctx.userId}:${(ctx as Context).pageId}`, |
| 224 | { last_parent_id: oldLastParentId }, |
| 225 | { dtrx }, |
| 226 | ); |
| 227 | |
| 228 | await ctx.dataAbstraction.patch( |
| 229 | 'user-page', |
| 230 | `${ctx.userId}:${destGroupOldMainPageId}`, |
| 231 | { last_parent_id: (ctx as Context).pageId }, |
| 232 | { dtrx }, |
| 233 | ); |
| 234 | } |
| 235 | |
| 236 | // Set page as main page of destination group |
| 237 | |
| 238 | await ctx.dataAbstraction.patch( |
| 239 | 'group', |
| 240 | (ctx as Context).destGroupId, |
| 241 | { main_page_id: (ctx as Context).pageId }, |
| 242 | { dtrx }, |
| 243 | ); |
| 244 | } |
| 245 | |
| 246 | // Moving page to a different group, reencrypt all page data |
| 247 | |
| 248 | if ((ctx as Context).sourceGroupId !== (ctx as Context).destGroupId) { |
| 249 | await ctx.dataAbstraction.patch( |
| 250 | 'page', |
| 251 | (ctx as Context).pageId, |
nothing calls this directly
no test coverage detected