MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / moveStep2

Function moveStep2

apps/app-server/src/websocket/pages/move.ts:194–309  ·  view source on GitHub ↗
({
  ctx,
  input,
}: InferProcedureOpts<typeof baseProcedureStep2>)

Source from the content-addressed store, hash-verified

192}
193
194export 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,

Callers

nothing calls this directly

Calls 12

hgetFunction · 0.90
patchMultipleFunction · 0.90
objEntriesFunction · 0.90
bumpRecentItemFunction · 0.90
transactionMethod · 0.80
patchMethod · 0.80
insertMethod · 0.80
addToTransactionMethod · 0.80
delMethod · 0.80
mhgetMethod · 0.45
hgetMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected