AND/OR groups should check if parameters exist before serializing
anthonycastelli opened this issue · 2 comments
anthonycastelli commented
SELECT * FROM "orders" WHERE ("orders"."canteenId" = $1 AND ()) ORDER BY "orders"."orderDate" DESC LIMIT 10 OFFSET 0 ["UUID (binary) 7Y&ˤ\u{1A}C��dã�ërI#)"]
return try req.parameters.next(Canteen.self).flatMap(to: Paginated<Order>.self) { canteen in
guard canteen.ownerId == owner.id else {
throw Abort(.badRequest, reason: "You do not have access to this canteen.")
}
let query = try canteen.orders.query(on: req)
try query.group(.and) { builder in
if let date = try req.query.get(Date?.self, at: "start") {
try builder.filter(\Order.orderDate >= date)
}
}
return try query.sort(\Order.orderDate, .descending).paginate(for: req)
}
Discord Discussion
tanner - Today at 11:05 AM
the group should probably check to make sure there are filters being applied before adding it
also the serializer should not serialize an empty group
two bugs there
tanner0101 commented
@anthonycastelli can you open an issue on vapor/sql for this? After looking at the code, that would be the best place to solve it 👍
anthonycastelli commented
Sure can!