Skip to content

Commit

Permalink
feat: delete logs for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
serezhaolshan committed Jan 7, 2025
1 parent 9f2558c commit f64d94c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/watcher/watcher.network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class WatcherNetwork {
async createWatcher(req: Request, res: Response): Promise<void> {
try {
const { push_token, device_id } = req.body;
console.log({ push_token, device_id });
await this.service.createWatcher(push_token, device_id);
res.json({ message: "Watcher created" });
} catch (error) {
Expand Down
26 changes: 4 additions & 22 deletions src/watcher/watcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,19 @@ export class WatcherService {
const encodedPushToken = Buffer.from(pushToken).toString("base64");

if (deviceId) {
console.log("Before getting watcher by device id");
const watcher = await this.watcherRepository.getWatcherByDeviceId(deviceId);
if (watcher) {
console.log("If watcher exists with this device id");
const decodedPushToken = Buffer.from(watcher.pushToken, "base64").toString("utf-8");
await this.deleteWatcher(decodedPushToken);
}
}

console.log("Before getting watcher");
const watcher = await this.watcherRepository.getWatcher(encodedPushToken);
if (watcher) {
console.log("If watcher exists with this push token");
throw new Error("watcher for this address and token already exists");
}
console.log("After getting watcher", { watcher });
if (watcher) throw new Error("watcher for this address and token already exists");

console.log("Before getting token price");
const tokenPrice = await this.cacheStorage.get("apiPrice");
if (!tokenPrice) {
console.log("If price data not found");
throw new Error("Price data not found");
}
console.log("After getting token price", { tokenPrice });
if (!tokenPrice) throw new Error("Price data not found");

await this.watcherRepository.createWatcher({
pushToken: encodedPushToken,
Expand Down Expand Up @@ -173,24 +162,17 @@ export class WatcherService {
}

async deleteWatcher(pushToken: string) {
console.log("Delete Watcher", pushToken);
const encodedPushToken = Buffer.from(pushToken).toString("base64");

console.log("Before getting watcher");
const watcher = await this.watcherRepository.getWatcher(encodedPushToken);
if (!watcher) {
console.log("If watcher not found");
throw new Error("watcher not found");
}

console.log("Before getting watcher addresses");
const watcherAddresses = await this.watcherAddressesService.getWatcherAddresses(watcher._id);
if (watcherAddresses.length > 0) {
console.log("If watcher addresses found");
await this.explorerService.unsubscribeAddresses(watcherAddresses);
}
if (watcherAddresses.length > 0) await this.explorerService.unsubscribeAddresses(watcherAddresses);


console.log("Before deleting watcher and watcher addresses");
await Promise.all([
this.watcherAddressesService.deleteAllWatcherAddresses(watcher._id),
this.watcherRepository.deleteWatcher({ pushToken: encodedPushToken }),
Expand Down

0 comments on commit f64d94c

Please sign in to comment.