Add multi-tenant SaaS: business signup, owner/branch-manager/staff hierarchy, full tenant isolation

This commit is contained in:
EOH Developer
2026-10-04 01:22:42 -07:00
parent 3b22ddf6fb
commit 04e3051eb6
38 changed files with 640 additions and 67 deletions
+5 -2
View File
@@ -23,7 +23,10 @@ export async function GET(req: NextRequest) {
const branchId = resolveBranchScope(auth, req.nextUrl.searchParams.get("branchId"));
const { start, end } = todayRange();
const matchStage: Record<string, unknown> = { createdAt: { $gte: start, $lt: end } };
const matchStage: Record<string, unknown> = {
businessId: new mongoose.Types.ObjectId(auth.businessId),
createdAt: { $gte: start, $lt: end },
};
if (branchId) matchStage.branchId = new mongoose.Types.ObjectId(branchId);
const [totals] = await Transaction.aggregate([
@@ -66,7 +69,7 @@ export async function GET(req: NextRequest) {
let branchRanking: any[] = [];
if (!branchId) {
branchRanking = await Transaction.aggregate([
{ $match: { createdAt: { $gte: start, $lt: end }, paymentStatus: "SUCCESS" } },
{ $match: { businessId: new mongoose.Types.ObjectId(auth.businessId), createdAt: { $gte: start, $lt: end }, paymentStatus: "SUCCESS" } },
{
$group: {
_id: "$branchId",