MCPcopy
hub / github.com/parse-community/parse-server / applyDuplicateDeviceTokenMerge

Function applyDuplicateDeviceTokenMerge

src/InstallationDedup.js:117–171  ·  view source on GitHub ↗
({
  database,
  idMatch,
  deviceTokenMatch,
  action,
  mergePriority,
  enforceAuth,
  runOptions,
  validSchemaController,
})

Source from the content-addressed store, hash-verified

115 * @returns {Promise<string>} survivor's objectId
116 */
117export async function applyDuplicateDeviceTokenMerge({
118 database,
119 idMatch,
120 deviceTokenMatch,
121 action,
122 mergePriority,
123 enforceAuth,
124 runOptions,
125 validSchemaController,
126}) {
127 // Self-merge guard: when both matches resolve to the same row, there's
128 // nothing to clean up. Skip the action so we don't destroy/update the row
129 // we're about to return as the survivor.
130 if (idMatch.objectId === deviceTokenMatch.objectId) {
131 return idMatch.objectId;
132 }
133 const opts = enforceAuth ? runOptions : {};
134 let loser;
135 let survivorId;
136 let fieldToClear;
137 if (mergePriority === 'deviceToken') {
138 loser = idMatch;
139 survivorId = deviceTokenMatch.objectId;
140 fieldToClear = 'installationId';
141 } else if (mergePriority === 'installationId') {
142 loser = deviceTokenMatch;
143 survivorId = idMatch.objectId;
144 fieldToClear = 'deviceToken';
145 } else {
146 throw new Error(`Unknown installation dedup mergePriority: ${mergePriority}`);
147 }
148
149 try {
150 await performAction({
151 database,
152 query: { objectId: loser.objectId },
153 action,
154 fieldToClear,
155 runOptions: opts,
156 many: false,
157 validSchemaController,
158 });
159 logResult(action, 1, null);
160 } catch (err) {
161 if (err && err.code === Parse.Error.OBJECT_NOT_FOUND) {
162 logResult(action, 0, err);
163 } else if (err && err.code === Parse.Error.OPERATION_FORBIDDEN) {
164 logResult(action, null, err);
165 } else {
166 logResult(action, null, err);
167 throw err;
168 }
169 }
170 return survivorId;
171}
172
173export default {
174 removeConflictingDeviceToken,

Callers

nothing calls this directly

Calls 2

performActionFunction · 0.85
logResultFunction · 0.85

Tested by

no test coverage detected