Interact in Service

When an order comes in, you need to inform the staff so that they can make ice cream, and when the ice cream is made, you need to notify the customer. Also, if the ice cream melts, you need to notify the customer again if they don't pick it up for a long time.
To achieve this, you need to add a service that sends periodic warnings if a served order is not finished, and a service that sends an alert message to the customer to remind them to pick up the order.

Declare Adapter

First, let's start by connecting an external API or module like an alert. You can connect an api that sends messages or emails, but in this tutorial, we'll create an api that simply prints to the console and connect it.
Modules like service, signal, document should not be directly connected to external systems, but rather created as adapters that are injected. First, let's create an adapter in the /nest folder as follows.
apps/koyo/nest/alarmApi.ts
Then, export the module in the /nest/index.ts file.
apps/koyo/nest/index.ts

Use External API

Now, in order to inject the adapter for the alarm into the server, you need to declare and register the adapter to be injected in the option.ts file.
apps/koyo/lib/option.ts
Now, you can inject the alarmApi in the icecreamOrderService and use it.
apps/koyo/lib/icecreamOrder/icecreamOrder.service.ts

Query in Document

Now, let's add a service function that sends a warning message if a served order is not finished. For easy testing, let's send a warning message after 15 seconds if the order is served.
apps/koyo/lib/icecreamOrder/icecreamOrder.service.ts
However, how can we query only the served icecream orders? To do this, let's create a list query function by utilizing the feature of creating a query based on the given conditions in the icecreamOrder.document file.
Now, let's apply the query to the document.
apps/koyo/lib/icecreamOrder/icecreamOrder.document.ts
By declaring the byStatuses query in IcecreamOrderFilter, you can use list, find, count, sample functions according to the given query conditions. For example, you can use listByStatuses, countByStatuses functions.

Use Interval

Now, let's use interval to execute the service every 15 seconds. The interval trigger is a trigger that works internally, and can be declared in IcecreamOrderInternal.
apps/koyo/lib/icecreamOrder/icecreamOrder.signal.ts
Now, you can see the warning message printed to the console if the order is served for more than 15 seconds.
Released under the MIT License
Official Akan.js Consulting onAkansoft
Copyright © 2025 Akan.js. All rights reserved.
System managed bybassman