Skip to content

Commit

Permalink
24 proof of concept for S3 upload. commented out validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-snodgrass committed Dec 21, 2023
1 parent 723be2d commit 95769a2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
14 changes: 13 additions & 1 deletion api/src/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
SQSClient,
} from '@aws-sdk/client-sqs'
import { getSignedUrl as awsGetSignedUrl } from '@aws-sdk/s3-request-presigner'
import { CreateUploadInput } from 'types/graphql'

const CPF_REPORTER_BUCKET_NAME = 'cpf-reporter'

function getS3Client() {
let s3: S3Client
Expand Down Expand Up @@ -38,7 +41,16 @@ function getS3Client() {
return s3
}

export async function sendPutObjectToS3Bucket(
export function uploadWorkbook(
upload: CreateUploadInput,
uploadId: number,
body: any

Check warning on line 47 in api/src/lib/aws.ts

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Unexpected any. Specify a different type
) {
const folderName = `${upload.organizationId}/${upload.agencyId}/${upload.reportingPeriodId}/uploads/${upload.expenditureCategoryId}/${uploadId}/${upload.filename}`
return sendPutObjectToS3Bucket(CPF_REPORTER_BUCKET_NAME, folderName, body)
}

async function sendPutObjectToS3Bucket(
bucketName: string,
key: string,
body: any

Check warning on line 56 in api/src/lib/aws.ts

View workflow job for this annotation

GitHub Actions / qa / Lint JavaScript

Unexpected any. Specify a different type
Expand Down
16 changes: 11 additions & 5 deletions api/src/services/uploads/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import type {
UploadRelationResolvers,
} from 'types/graphql'

import { uploadWorkbook } from 'src/lib/aws'
import { db } from 'src/lib/db'
import { validateUpload } from 'src/lib/validate-upload'

export const uploads: QueryResolvers['uploads'] = () => {
return db.upload.findMany()
}
Expand All @@ -17,11 +16,18 @@ export const upload: QueryResolvers['upload'] = ({ id }) => {
})
}

export const createUpload: MutationResolvers['createUpload'] = ({ input }) => {
validateUpload(input, context.currentUser)
return db.upload.create({
export const createUpload: MutationResolvers['createUpload'] = async ({
input,
}) => {
// validateUpload(input, context.currentUser)
const upload = await db.upload.create({
data: input,
})
console.log('input', input)
console.log('upload', upload)
await uploadWorkbook(upload, upload.id, 'Hello World')

return upload
}

export const updateUpload: MutationResolvers['updateUpload'] = ({
Expand Down
18 changes: 13 additions & 5 deletions web/src/components/Upload/UploadForm/UploadForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Form,
FileField,
SelectField,
HiddenField,
// HiddenField,
FormError,
FieldError,
Label,
Expand All @@ -15,11 +15,11 @@ import {
} from '@redwoodjs/forms'
import type { RWGqlError } from '@redwoodjs/forms'

type FormUpload = NonNullable<EditUploadById['upload']>
// type FormUpload = NonNullable<EditUploadById['upload']>

interface UploadFormProps {
upload?: EditUploadById['upload']
onSave: (data: UpdateUploadInput, id?: FormUpload['id']) => void
onSave: (data: UpdateUploadInput) => void
error: RWGqlError
loading: boolean
}
Expand All @@ -31,8 +31,16 @@ const UploadForm = (props: UploadFormProps) => {
data.filename = data.file[0].name
data.agencyId = parseInt(data.agencyId)
data.reportingPeriodId = parseInt(data.reportingPeriodId)
console.log(data)
props.onSave({ filename: data.file[0].name }, props?.upload?.id)
// console.log(data)

props.onSave({
uploadedById: 1,
agencyId: 1,
filename: data.file[0].name,
organizationId: 1,
reportingPeriodId: data.reportingPeriodId,
expenditureCategoryId: 1,
})
}

const onReset = () => {
Expand Down

0 comments on commit 95769a2

Please sign in to comment.