Skip to content

Instantly share code, notes, and snippets.

@bibscy
Created August 10, 2018 21:07
Show Gist options
  • Save bibscy/64ba73b88868d91ab9c3987d51da3c78 to your computer and use it in GitHub Desktop.
Save bibscy/64ba73b88868d91ab9c3987d51da3c78 to your computer and use it in GitHub Desktop.
extension NotificationsMyStreet {
func prepareVars(request:Request) throws -> DataFromClientSendNotifications {
struct ObjectReceived: NodeInitializable {
let title: String
let body: String
let unreadMessagesCount: Int
init(node: Node, in context: Context = EmptyNode) throws {
title = try node.extract()
body = try node.extract()
unreadMessagesCount = try node.extract()
}
}
guard let json = request.json else {
throw Abort.custom(status: .badRequest, message: "something went ")
}
let objects = try json.object?.values.map { try ObjectReceived(node: $0 as! Node) } ?? []
print(objects)
}//end of func prepareVars
}//end of extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment