| @@ -645,27 +645,31 @@ struct FuelEntryV2ControllerV2_1: RouteCollection { | |||||
| func create(req: Request) async throws -> [FuelEntry] { | func create(req: Request) async throws -> [FuelEntry] { | ||||
| let fuelEntry = try req.content.decode([FuelEntry].self) | |||||
| let fuelEntry = try req.content.decode([FuelEntry.V2_1_Input].self) | |||||
| var results: [FuelEntry] = [] | |||||
| for entry in fuelEntry { | for entry in fuelEntry { | ||||
| let input = try FuelEntry.init(from: entry) | |||||
| let data = entry.image ?? nil | let data = entry.image ?? nil | ||||
| let length = data?.count | let length = data?.count | ||||
| if(data == nil || length == 0){ | if(data == nil || length == 0){ | ||||
| entry.image = nil | |||||
| input.image = nil | |||||
| } | } | ||||
| if(entry.id != nil){ | if(entry.id != nil){ | ||||
| let dbentry = try await FuelEntry.find(entry.id!, on: req.db) | |||||
| if(dbentry != nil){ | |||||
| entry._$idExists = true | |||||
| if (try await FuelEntry.find(entry.id!, on: req.db)) != nil { | |||||
| input._$id.exists = true | |||||
| } else { | |||||
| input._$idExists = false | |||||
| } | } | ||||
| } | } | ||||
| entry.save(on: req.db).whenFailure({ error in | |||||
| input.save(on: req.db).whenFailure({ error in | |||||
| }) | }) | ||||
| results.append(input) | |||||
| } | } | ||||
| // try await fuelEntry.create(on: req.db) | // try await fuelEntry.create(on: req.db) | ||||
| return fuelEntry | |||||
| return results | |||||
| } | } | ||||