Skip to content

Commit

Permalink
bbugs fixed (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrobaina authored Nov 27, 2023
1 parent 0474052 commit 7683198
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/useCases/petCases/createMedicalRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { prisma } from '../../database/prisma'

export const createMedicalRecord = async (req: Request, res: Response) => {
try {
console.log('req.body', req.body)

const cleanedData = cleanData({
...req.body,
})
Expand Down Expand Up @@ -45,7 +43,13 @@ const cleanData = (obj: Record<string, any>): Record<string, any> => {
const newObj: Record<string, any> = {}

for (let [key, value] of Object.entries(obj)) {
if (value === '' || value === null || value === undefined) continue
if (
value === '' ||
value === null ||
value === 'null' ||
value === undefined
)
continue
if (key === 'attachments') continue
if (key === 'newAttachments') continue

Expand Down
14 changes: 7 additions & 7 deletions src/useCases/petCases/updateMedicalRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ const cleanData = (obj: Record<string, any>): Record<string, any> => {
const newObj: Record<string, any> = {}

for (let [key, value] of Object.entries(obj)) {
if (
value == null ||
value === '' ||
key === 'id' ||
key === 'followUpRequired' ||
key === 'followUpDate'
)
if (key === 'id' || key === 'followUpRequired' || key === 'followUpDate')
continue

if (key === 'vetId' && value === 'null') {
newObj[key] = null
continue
}

newObj[key] =
typeof value === 'object' && !Array.isArray(value)
? cleanData(value)
Expand All @@ -90,6 +89,7 @@ const cleanData = (obj: Record<string, any>): Record<string, any> => {

if (newObj.newAttachments) delete newObj.newAttachments
if (newObj.deleteAttachments) delete newObj.deleteAttachments
console.log(1, newObj)

return newObj
}
Expand Down

0 comments on commit 7683198

Please sign in to comment.