Refactor to vertical slice
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { db } from '@/lib/prisma';
|
||||
import { parsePlanRules } from '@/modules/plan/services/plan-rules.service';
|
||||
|
||||
export async function getCurrentComplex(userId: string, complexId: string) {
|
||||
const complexUser = await db.complexUser.findUnique({
|
||||
where: {
|
||||
complexId_userId: {
|
||||
complexId,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
complex: {
|
||||
include: {
|
||||
plan: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!complexUser) return null;
|
||||
|
||||
return {
|
||||
...complexUser.complex,
|
||||
role: complexUser.role,
|
||||
planFeatures: complexUser.complex.plan
|
||||
? parsePlanRules(complexUser.complex.plan.rules).features
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function selectComplex(userId: string, complexId: string) {
|
||||
return getCurrentComplex(userId, complexId);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { AppContext } from '@/types/hono';
|
||||
import { getCookie } from 'hono/cookie';
|
||||
import { getCurrentComplex } from './get-current-complex.business';
|
||||
|
||||
const SELECTED_COMPLEX_COOKIE = 'selected-complex-id';
|
||||
|
||||
export async function getCurrentComplexHandler(c: AppContext) {
|
||||
const user = c.get('user');
|
||||
const complexId = getCookie(c, SELECTED_COMPLEX_COOKIE);
|
||||
|
||||
if (!complexId) {
|
||||
return c.json(null);
|
||||
}
|
||||
|
||||
const complex = await getCurrentComplex(user.id, complexId);
|
||||
|
||||
if (!complex) {
|
||||
return c.json(null);
|
||||
}
|
||||
|
||||
return c.json(complex);
|
||||
}
|
||||
Reference in New Issue
Block a user