Parameters
type
Defines the type of gift that will be generated, such as coin, discount, premium, etc.
index.js
const { GiftManager } = require("atosjs");
const gift = new GiftManager();
(async () => {
const coin = await gift.generate({
type: 'coin', // The 'type' is usually used to define the gift's name.
});
console.log({
code: coin,
});
})();value
Determines the value associated with the gift. It can be a number, string, or even a custom object.
index.js
const { GiftManager } = require("atosjs");
const gift = new GiftManager();
(async () => {
const coin = await gift.generate({
value: 1500, // The 'value' is used to define the value of the gift.
});
console.log({
code: coin,
});
})();edit
Allows customization of the gift code instead of automatically generating a random code.
index.js
const { GiftManager } = require("atosjs");
const gift = new GiftManager();
(async () => {
const promotion = await gift.generate({
edit: {
code: "NATAL2025" // The 'edit' is used to set a specific code instead of generating a random code.
maxRedeem: 12, // 'maxRedeem' is used to set the number of times the gift can be used.
expiration: '30d', // 'expiration' is used to set the gift's validity period.
},
});
console.log({
code: promotion,
});
})();What is codeId();?
codeId is the internal random code generator used by the generate method.
For example, calling codeId(); might give you a result like 6HFDB6RPYSCLR. Here is a full example:
index.js
const { GiftManager, codeId } = require("atosjs");
const gift = new GiftManager();
(async () => {
const editedCode = await gift.generate({
edit: {
code: "test-" + codeId()
},
});
console.log({
giftId: editedCode,
});
})();Expected result, after running the file:
Terminal
✔ Connected to 🚀 AtosDB (json.sqlite) 2:24:20 AM
{ giftId: 'test-RJASYXQTVBKK3' }General summary of
await gift.generate();
| Option | Type | Default | Description |
|---|---|---|---|
type | string | undefined | Defines the type of the gift. Example: discount, premium, coins. |
value | unknown | undefined | Defines the value of the gift. Example: 100, 'VIP Access', { wallet: { coins: 5000 } }. |
edit | { code: string, expiration: string, maxRedeem: number } | undefined | Allows customizing the code, setting expiration (expiration), and maximum redemptions (maxRedeem). Example: { code: 'NATAL2025', expiration: '7d', maxRedeem: 5 }. |
edit.expiration | string | undefined | Defines the expiration date of the gift. Example: '60s', '7d', '1y'. |
edit.maxRedeem | number | undefined | Limits the number of times the gift can be redeemed. Default is 1. Example: 5. |
Last updated on: