bug fix - wrong function angrument

This commit is contained in:
Patryk Drzewiński 2022-06-12 19:11:44 +02:00
parent d6c0bd189b
commit bdad456637
3 changed files with 5 additions and 4 deletions

View File

@ -100,8 +100,9 @@ def create_student(data: dict) -> dict:
@bp.route("/upload/", methods=["POST"]) @bp.route("/upload/", methods=["POST"])
@bp.input(FileSchema, location='form_and_files') @bp.input(FileSchema, location='form_and_files')
@bp.output(MessageSchema) @bp.output(MessageSchema)
def upload_students(file: dict, mode: bool) -> dict: def upload_students(file: dict) -> dict:
uploaded_file = file.get('file') uploaded_file = file.get('file')
mode = file.get('mode') == '0'
if uploaded_file and is_allowed_extensions(uploaded_file.filename): if uploaded_file and is_allowed_extensions(uploaded_file.filename):
try: try:

View File

@ -34,9 +34,8 @@ export const getStudents = (
export const createStudent = (payload: Student) => export const createStudent = (payload: Student) =>
axiosInstance.post('http://127.0.0.1:5000/api/coordinator/students/', payload) axiosInstance.post('http://127.0.0.1:5000/api/coordinator/students/', payload)
export const uploadStudents = (payload: FormData, mode: Boolean) => export const uploadStudents = (payload: FormData) =>
axiosInstance.post( axiosInstance.post(
'http://127.0.0.1:5000/api/coordinator/students/upload/', 'http://127.0.0.1:5000/api/coordinator/students/upload/',
payload, payload,
mode,
) )

View File

@ -40,7 +40,7 @@ const Students = () => {
const { mutate: mutateUpload } = useMutation( const { mutate: mutateUpload } = useMutation(
'uploadStudents', 'uploadStudents',
(payload: FormData) => uploadStudents(payload, mode), (payload: FormData) => uploadStudents(payload),
{ {
onSuccess: () => refetchStudents(), onSuccess: () => refetchStudents(),
}, },
@ -50,6 +50,7 @@ const Students = () => {
const file = event.target.files[0] const file = event.target.files[0]
const payload = new FormData() const payload = new FormData()
payload.append('file', file, file.name) payload.append('file', file, file.name)
payload.append('mode', mode ? '0' : '1')
mutateUpload(payload) mutateUpload(payload)
} }