I'll provide you with all the files needed for the Strapi project based on the PRD. Here's the complete file structure with content:
Project Structure Overview
aeria-employee-app/
├── config/
│ ├── database.js
│ └── plugins.js
├── src/
│ ├── api/
│ │ ├── gift/
│ │ │ ├── content-types/
│ │ │ │ └── gift/
│ │ │ │ └── schema.json
│ │ │ ├── controllers/
│ │ │ │ └── gift.ts
│ │ │ ├── routes/
│ │ │ │ └── gift.ts
│ │ │ └── services/
│ │ │ └── gift.ts
│ │ ├── gift-allocation/
│ │ │ ├── content-types/
│ │ │ │ └── gift-allocation/
│ │ │ │ └── schema.json
│ │ │ ├── controllers/
│ │ │ │ └── gift-allocation.ts
│ │ │ ├── routes/
│ │ │ │ └── gift-allocation.ts
│ │ │ └── services/
│ │ │ └── gift-allocation.ts
│ │ └── audit-log/
│ │ ├── content-types/
│ │ │ └── audit-log/
│ │ │ └── schema.json
│ │ ├── controllers/
│ │ │ └── audit-log.ts
│ │ ├── routes/
│ │ │ └── audit-log.ts
│ │ └── services/
│ │ └── audit-log.ts
│ ├── extensions/
│ │ └── users-permissions/
│ │ └── content-types/
│ │ └── user/
│ │ └── schema.json
│ └── utils/
│ ├── gift-logic.ts
│ ├── jwt-helper.ts
│ └── validation.ts
├── package.json
└── tsconfig.json
File Contents
1. /package.json
{
"name": "aeria-employee-app",
"private": true,
"version": "0.1.0",
"description": "Aeria Employee App Gift Claim Module",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"dependencies": {
"@strapi/strapi": "4.15.5",
"@strapi/plugin-users-permissions": "4.15.5",
"@strapi/plugin-i18n": "4.15.5",
"better-sqlite3": "8.6.0",
"jsonwebtoken": "^9.0.2",
"moment": "^2.29.4"
},
"devDependencies": {
"@types/node": "^20.10.0",
"@types/jsonwebtoken": "^9.0.5",
"typescript": "^5.3.0",
"ts-node": "^10.9.0"
},
"author": {
"name": "Aeria Team"
},
"strapi": {
"uuid": "aeria-employee-app"
},
"engines": {
"node": ">=14.19.1 <=20.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
2. /tsconfig.json
{
"compilerOptions": {
"target": "ES2019",
"module": "commonjs",
"lib": ["ES2019"],
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"allowJs": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", ".cache", "build", ".strapi-updater.json"]
}
3. /config/database.js
module.exports = ({ env }) => ({
connection: {
client: 'sqlite',
connection: {
filename: env('DATABASE_FILENAME', '.tmp/data.db'),
},
useNullAsDefault: true,
},
});
4. /config/plugins.js
module.exports = ({ env }) => ({
'users-permissions': {
config: {
jwt: {
expiresIn: '7d',
},
},
},
});
5. /src/extensions/users-permissions/content-types/user/schema.json
{
"kind": "collectionType",
"collectionName": "up_users",
"info": {
"name": "user",
"description": "",
"singularName": "user",
"pluralName": "users",
"displayName": "User"
},
"options": {
"draftAndPublish": false,
"timestamps": true
},
"attributes": {
"username": {
"type": "string",
"minLength": 3,
"unique": true,
"configurable": false,
"required": true
},
"email": {
"type": "email",
"minLength": 6,
"configurable": false,
"required": true
},
"provider": {
"type": "string",
"configurable": false
},
"password": {
"type": "password",
"minLength": 6,
"configurable": false,
"private": true
},
"resetPasswordToken": {
"type": "string",
"configurable": false,
"private": true
},
"confirmationToken": {
"type": "string",
"configurable": false,
"private": true
},
"confirmed": {
"type": "boolean",
"default": false,
"configurable": false
},
"blocked": {
"type": "boolean",
"default": false,
"configurable": false
},
"role": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.role",
"inversedBy": "users",
"configurable": false
},
"upin": {
"type": "string",
"required": true,
"unique": true,
"minLength": 6,
"maxLength": 20
},
"firstLoginAt": {
"type": "datetime"
},
"totalLogins": {
"type": "integer",
"default": 0
}
}
}
6. /src/api/gift/content-types/gift/schema.json
{
"kind": "collectionType",
"collectionName": "gifts",
"info": {
"singularName": "gift",
"pluralName": "gifts",
"displayName": "Gift",
"description": "Gift configuration for rewards"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"title": {
"type": "string",
"required": true
},
"description": {
"type": "text",
"required": true
},
"image": {
"type": "media",
"multiple": false,
"required": false,
"allowedTypes": ["images"]
},
"inventory": {
"type": "integer",
"default": 0,
"min": 0,
"required": true
},
"frequency": {
"type": "json",
"required": true
},
"timeWindow": {
"type": "json",
"required": false
},
"probability": {
"type": "float",
"default": 1.0,
"min": 0,
"max": 1,
"required": true
},
"claimedExpiry": {
"type": "integer",
"default": 30,
"min": 1,
"required": true
},
"unclaimedExpiry": {
"type": "integer",
"default": 7,
"min": 1,
"required": true
},
"howToAvail": {
"type": "richtext",
"required": true
},
"termsAndConditions": {
"type": "richtext",
"required": true
},
"isActive": {
"type": "boolean",
"default": true,
"required": true
},
"priority": {
"type": "integer",
"default": 0
},
"thirdPartyUrl": {
"type": "string",
"required": true
}
}
}
7. /src/api/gift-allocation/content-types/gift-allocation/schema.json
{
"kind": "collectionType",
"collectionName": "gift_allocations",
"info": {
"singularName": "gift-allocation",
"pluralName": "gift-allocations",
"displayName": "Gift Allocation",
"description": "Tracks gift assignments to users"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"user": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.user",
"required": true
},
"upin": {
"type": "string",
"required": true
},
"deviceId": {
"type": "string",
"required": true
},
"gift": {
"type": "relation",
"relation": "manyToOne",
"target": "api::gift.gift",
"required": true
},
"assignedAt": {
"type": "datetime",
"required": true
},
"claimedAt": {
"type": "datetime"
},
"expiryAt": {
"type": "datetime",
"required": true
},
"status": {
"type": "enumeration",
"enum": ["unclaimed", "claimed", "expired"],
"default": "unclaimed",
"required": true
},
"claimToken": {
"type": "string",
"private": true
},
"notificationsSent": {
"type": "integer",
"default": 0
}
}
}
8. /src/api/audit-log/content-types/audit-log/schema.json
{
"kind": "collectionType",
"collectionName": "audit_logs",
"info": {
"singularName": "audit-log",
"pluralName": "audit-logs",
"displayName": "Audit Log",
"description": "Tracks admin actions and system events"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"action": {
"type": "string",
"required": true
},
"operator": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.user"
},
"target": {
"type": "json",
"required": true
},
"timestamp": {
"type": "datetime",
"required": true
},
"reason": {
"type": "text"
},
"metadata": {
"type": "json"
}
}
}
9. /src/api/gift/controllers/gift.ts
import { factories } from '@strapi/strapi';
import { hasAlreadyWonGift, isFrequencyValid, isTimeWindowValid, calculateExpiry } from '../../../utils/gift-logic';
import { createAuditLog } from '../../audit-log/services/audit-log';
export default factories.createCoreController('api::gift.gift', ({ strapi }) => ({
async assign(ctx) {
try {
const { userId, upin, deviceId } = ctx.request.body;
if (!userId || !upin || !deviceId) {
return ctx.badRequest('Missing required fields: userId, upin, deviceId');
}
// Get user and validate
const user = await strapi.entityService.findOne('plugin::users-permissions.user', userId);
if (!user) {
return ctx.notFound('User not found');
}
// Update first login if needed
if (!user.firstLoginAt) {
await strapi.entityService.update('plugin::users-permissions.user', userId, {
data: {
firstLoginAt: new Date(),
totalLogins: (user.totalLogins || 0) + 1
}
});
}
// Get total eligible logins for frequency calculation
const totalEligibleLogins = await strapi.db.query('plugin::users-permissions.user').count({
where: { firstLoginAt: { $notNull: true } }
});
// Get active gifts sorted by priority
const activeGifts = await strapi.entityService.findMany('api::gift.gift', {
filters: { isActive: true, inventory: { $gt: 0 } },
sort: { priority: 'desc' }
});
// Try to assign a gift
for (const gift of activeGifts) {
const hasWon = await hasAlreadyWonGift(strapi, userId, upin, deviceId, gift.id);
if (
!hasWon &&
isFrequencyValid(gift, totalEligibleLogins) &&
isTimeWindowValid(gift, new Date()) &&
Math.random() < gift.probability
) {
// Create allocation
const allocation = await strapi.entityService.create('api::gift-allocation.gift-allocation', {
data: {
user: userId,
upin,
deviceId,
gift: gift.id,
assignedAt: new Date(),
expiryAt: calculateExpiry(gift, 'unclaimed'),
status: 'unclaimed'
}
});
// Decrement inventory
await strapi.entityService.update('api::gift.gift', gift.id, {
data: { inventory: gift.inventory - 1 }
});
// Create audit log
await createAuditLog(strapi, {
action: 'gift_assigned',
operator: null,
target: { userId, giftId: gift.id, allocationId: allocation.id },
reason: 'First login gift assignment'
});
return ctx.send({
success: true,
allocation: {
id: allocation.id,
gift: {
id: gift.id,
title: gift.title,
description: gift.description,
image: gift.