File size: 660 Bytes
0dd2082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function success(res, data, statusCode = 200) {
    return res.status(statusCode).json({
        success: true,
        timestamp: new Date().toISOString(),
        ...data,
    });
}

function paginate(items, page = 1, limit = 10) {
    const start = (page - 1) * limit;
    const end = start + limit;
    const results = items.slice(start, end);
    return {
        results,
        pagination: {
            page,
            limit,
            total: items.length,
            totalPages: Math.ceil(items.length / limit),
            hasNext: end < items.length,
            hasPrev: page > 1,
        },
    };
}

module.exports = { success, paginate };