(input: InsertWantedInput)
| 58 | * (id, title) and returns a single multi-row INSERT statement. |
| 59 | */ |
| 60 | export function insertWantedDML(input: InsertWantedInput): string { |
| 61 | if (input.id === '') throw new Error('wanted item ID cannot be empty'); |
| 62 | if (input.title === '') throw new Error('wanted item title cannot be empty'); |
| 63 | |
| 64 | const now = input.now ?? formatNowUtc(new Date()); |
| 65 | const tagsJson = formatTagsJson(input.tags); |
| 66 | |
| 67 | const descField = sqlStringOrNull(input.description); |
| 68 | const projectField = sqlStringOrNull(input.project); |
| 69 | const typeField = sqlStringOrNull(input.type); |
| 70 | const postedByField = sqlStringOrNull(input.postedBy); |
| 71 | const effortField = |
| 72 | input.effortLevel && input.effortLevel !== '' |
| 73 | ? `'${escapeSqlString(input.effortLevel)}'` |
| 74 | : "'medium'"; |
| 75 | const status = |
| 76 | input.status && input.status !== '' ? `'${escapeSqlString(input.status)}'` : "'open'"; |
| 77 | const priority = input.priority ?? 0; |
| 78 | |
| 79 | return ( |
| 80 | `INSERT INTO wanted (id, title, description, project, type, priority, tags, posted_by, status, effort_level, created_at, updated_at)\n` + |
| 81 | `VALUES ('${escapeSqlString(input.id)}', '${escapeSqlString(input.title)}', ${descField}, ${projectField}, ${typeField}, ${priority}, ${tagsJson}, ${postedByField}, ${status}, ${effortField}, '${now}', '${now}')` |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | // ClaimWantedDML (commons.go:329) |
| 86 |
no test coverage detected