user module

This commit is contained in:
2026-01-13 19:59:06 +03:30
parent 6522acff5f
commit d630cb844a
62 changed files with 1137 additions and 3040 deletions
@@ -12,24 +12,25 @@ export class SmsLogRepository extends EntityRepository<SmsLog> {
async getSmsCountByRestaurant(
page: number = 1,
limit: number = 10,
): Promise<PaginatedResult<{ restaurantId: string; restaurantName: string; smsCount: number }>> {
const offset = (page - 1) * limit;
): Promise<PaginatedResult<{ : string; restaurantName: string; smsCount: number
}>> {
const offset = (page - 1) * limit;
// Get total count of unique restaurants with SMS logs
const totalResult = await this.em.execute(
`
// Get total count of unique restaurants with SMS logs
const totalResult = await this.em.execute(
`
SELECT COUNT(DISTINCT sl.restaurant_id) as total
FROM sms_logs sl
WHERE sl.restaurant_id IS NOT NULL
`,
);
const total = parseInt(totalResult[0]?.total || '0', 10);
);
const total = parseInt(totalResult[0]?.total || '0', 10);
// Get paginated results with SMS counts grouped by restaurant
const results = await this.em.execute(
`
// Get paginated results with SMS counts grouped by restaurant
const results = await this.em.execute(
`
SELECT
r.id as "restaurantId",
r.id as "",
r.name as "restaurantName",
COUNT(sl.id)::int as "smsCount"
FROM sms_logs sl
@@ -38,39 +39,39 @@ export class SmsLogRepository extends EntityRepository<SmsLog> {
ORDER BY "smsCount" DESC, r.name ASC
LIMIT ? OFFSET ?
`,
[limit, offset],
);
[limit, offset],
);
const data = results.map((row: any) => ({
restaurantId: row.restaurantId,
restaurantName: row.restaurantName || 'Unknown',
smsCount: parseInt(row.smsCount || '0', 10),
}));
const data = results.map((row: any) => ({
: row.,
restaurantName: row.restaurantName || 'Unknown',
smsCount: parseInt(row.smsCount || '0', 10),
}));
const totalPages = Math.ceil(total / limit);
const totalPages = Math.ceil(total / limit);
return {
data,
meta: {
total,
page,
limit,
totalPages,
},
};
}
return {
data,
meta: {
total,
page,
limit,
totalPages,
},
};
}
async getSmsCountByRestaurantId(restaurantId: string): Promise<number> {
const result = await this.em.execute(
`
async getSmsCountBy(: string): Promise < number > {
const result = await this.em.execute(
`
SELECT COUNT(sl.id)::int as "smsCount"
FROM sms_logs sl
WHERE sl.restaurant_id = ?
`,
[restaurantId],
);
[],
);
return parseInt(result[0]?.smsCount || '0', 10);
}
return parseInt(result[0]?.smsCount || '0', 10);
}
}