Skip to content

Commit

Permalink
🔊 (AccountKit): Add logs to DatabaseOperations
Browse files Browse the repository at this point in the history
  • Loading branch information
macteuts committed Feb 14, 2024
1 parent 26eb71c commit 5938816
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Modules/AccountKit/Sources/Database/DatabaseOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class DatabaseOperations {
if let error {
promise(.failure(DatabaseError.customError(error.localizedDescription)))
} else {
log.info("Document \(String(describing: documentData.id)) created successfully. 🎉")
promise(.success(documentData))
}
}
} catch {
log.error("\(error.localizedDescription)")
promise(.failure(error))
}
}
Expand All @@ -47,11 +49,13 @@ public class DatabaseOperations {
do {
let object = try document?.data(as: T.self)
if let object {
log.info("Document \(String(describing: object.id)) fetched successfully. 🎉")
promise(.success(object))
} else {
promise(.failure(DatabaseError.documentNotFound))
}
} catch {
log.error("\(error.localizedDescription)")
promise(.failure(error))
}
}
Expand All @@ -65,11 +69,13 @@ public class DatabaseOperations {
self.database.collection(collection.rawValue)
.getDocuments { querySnapshot, error in
if let error {
log.error("\(error.localizedDescription)")
promise(.failure(error))
} else {
let objects = querySnapshot?.documents.compactMap { document -> T? in
try? document.data(as: T.self)
} ?? []
log.info("\(String(describing: objects.count)) documents fetched successfully. 🎉")
promise(.success(objects))
}
}
Expand Down

0 comments on commit 5938816

Please sign in to comment.