b15d5b836c
* fix(server): remove redundant code from bad merge * wrong router * WIP: http api for receiving file import results * Lints * fix * WIP: tests * test fix * auth middleware has implicit requirement for param named streamId * complete tests and fixes * can run the old way alongside the existing, no conflicts * tidying * correct error thrown * feat(fileUploads): new upload endpoint skeleton * feat(fileUploads): added coverage for new file importer endpoint * fix(workspaces): added tests, fix bugged on handling after stream * refactor: removed useless file * fix: comments, added tests * feat: added modelId to file upload table * fix: ensureError log --------- Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>
22 lines
732 B
TypeScript
22 lines
732 B
TypeScript
import { randomInt } from 'crypto'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
import { saveUploadFileFactory } from '@/modules/fileuploads/repositories/fileUploads'
|
|
import { db } from '@/db/knex'
|
|
|
|
const saveUploadFile = saveUploadFileFactory({ db })
|
|
export const createFileUploadJob = (params: { projectId: string; userId: string }) => {
|
|
const { projectId, userId } = params
|
|
const jobId = cryptoRandomString({ length: 10 })
|
|
const data = {
|
|
fileId: jobId,
|
|
streamId: projectId,
|
|
branchName: cryptoRandomString({ length: 10 }),
|
|
userId,
|
|
fileName: cryptoRandomString({ length: 10 }),
|
|
fileType: cryptoRandomString({ length: 3 }),
|
|
fileSize: randomInt(1, 1e6)
|
|
}
|
|
|
|
return saveUploadFile(data)
|
|
}
|