(input: AcceptUpstreamInput)
| 213 | * fork completion, UPDATE wanted, INSERT stamp, UPDATE completion w/ stamp ref. |
| 214 | */ |
| 215 | export function acceptUpstreamDML(input: AcceptUpstreamInput): string[] { |
| 216 | const tagsField = formatTagsJson(input.stamp.skillTags); |
| 217 | const msgField = sqlStringOrNull(input.stamp.message); |
| 218 | const hopField = sqlStringOrNull(input.hopUri); |
| 219 | |
| 220 | const valence = `{"quality": ${input.stamp.quality}, "reliability": ${input.stamp.reliability}}`; |
| 221 | |
| 222 | const deleteCompletion = `DELETE FROM completions WHERE wanted_id='${escapeSqlString(input.wantedId)}'`; |
| 223 | |
| 224 | const insertCompletion = |
| 225 | `INSERT IGNORE INTO completions (id, wanted_id, completed_by, evidence, hop_uri, completed_at) ` + |
| 226 | `VALUES ('${escapeSqlString(input.completionId)}', '${escapeSqlString(input.wantedId)}', ` + |
| 227 | `'${escapeSqlString(input.completedBy)}', '${escapeSqlString(input.evidence)}', ${hopField}, NOW())`; |
| 228 | |
| 229 | const updateWanted = |
| 230 | `UPDATE wanted SET status='completed', claimed_by='${escapeSqlString(input.completedBy)}', ` + |
| 231 | `evidence_url='${escapeSqlString(input.evidence)}', updated_at=NOW() ` + |
| 232 | `WHERE id='${escapeSqlString(input.wantedId)}'`; |
| 233 | |
| 234 | const insertStamp = |
| 235 | `INSERT INTO stamps (id, author, subject, valence, confidence, severity, context_id, context_type, skill_tags, message, hop_uri, created_at) ` + |
| 236 | `VALUES ('${escapeSqlString(input.stamp.id)}', '${escapeSqlString(input.rigHandle)}', ` + |
| 237 | `'${escapeSqlString(input.stamp.subject)}', '${escapeSqlString(valence)}', 1.0, ` + |
| 238 | `'${escapeSqlString(input.stamp.severity)}', '${escapeSqlString(input.completionId)}', 'completion', ` + |
| 239 | `${tagsField}, ${msgField}, ${hopField}, NOW())`; |
| 240 | |
| 241 | const updateCompletion = |
| 242 | `UPDATE completions SET validated_by='${escapeSqlString(input.rigHandle)}', ` + |
| 243 | `stamp_id='${escapeSqlString(input.stamp.id)}', validated_at=NOW() ` + |
| 244 | `WHERE id='${escapeSqlString(input.completionId)}'`; |
| 245 | |
| 246 | return [deleteCompletion, insertCompletion, updateWanted, insertStamp, updateCompletion]; |
| 247 | } |
| 248 | |
| 249 | // CloseUpstreamDML (commons.go:751) |
| 250 |
no test coverage detected