mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 15:54:03 +00:00
feat(member): add household lifecycle states
This commit is contained in:
@@ -178,6 +178,7 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -191,6 +192,7 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -212,6 +214,7 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId,
|
telegramUserId,
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: locale,
|
preferredLocale: locale,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -249,7 +252,8 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
isActive: input.isActive
|
isActive: input.isActive
|
||||||
}),
|
}),
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,6 +355,7 @@ describe('registerAnonymousFeedback', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: 'en',
|
preferredLocale: 'en',
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ function createRepository(isAdmin = false): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: 'ru',
|
preferredLocale: 'ru',
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -131,7 +132,8 @@ function createRepository(isAdmin = false): HouseholdConfigurationRepository {
|
|||||||
},
|
},
|
||||||
updateMemberPreferredLocale: async () => null,
|
updateMemberPreferredLocale: async () => null,
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ function createHouseholdRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'en',
|
householdDefaultLocale: 'en',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -180,6 +181,7 @@ function createHouseholdRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'en',
|
householdDefaultLocale: 'en',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -191,7 +193,8 @@ function createHouseholdRepository(): HouseholdConfigurationRepository {
|
|||||||
updateHouseholdDefaultLocale: async () => household,
|
updateHouseholdDefaultLocale: async () => household,
|
||||||
updateMemberPreferredLocale: async () => null,
|
updateMemberPreferredLocale: async () => null,
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ function createRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: 'ru',
|
preferredLocale: 'ru',
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -109,7 +110,8 @@ function createRepository(): HouseholdConfigurationRepository {
|
|||||||
},
|
},
|
||||||
updateMemberPreferredLocale: async () => null,
|
updateMemberPreferredLocale: async () => null,
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? existing?.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? existing?.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? existing?.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: input.rentShareWeight ?? existing?.rentShareWeight ?? 1,
|
rentShareWeight: input.rentShareWeight ?? existing?.rentShareWeight ?? 1,
|
||||||
@@ -456,6 +457,7 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
householdId: pending.householdId,
|
householdId: pending.householdId,
|
||||||
telegramUserId: pending.telegramUserId,
|
telegramUserId: pending.telegramUserId,
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: pending.householdDefaultLocale,
|
householdDefaultLocale: pending.householdDefaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -492,6 +494,9 @@ function createHouseholdConfigurationRepository(): HouseholdConfigurationReposit
|
|||||||
},
|
},
|
||||||
async updateHouseholdMemberRentShareWeight() {
|
async updateHouseholdMemberRentShareWeight() {
|
||||||
return null
|
return null
|
||||||
|
},
|
||||||
|
async updateHouseholdMemberStatus() {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import {
|
|||||||
createMiniAppPendingMembersHandler,
|
createMiniAppPendingMembersHandler,
|
||||||
createMiniAppPromoteMemberHandler,
|
createMiniAppPromoteMemberHandler,
|
||||||
createMiniAppSettingsHandler,
|
createMiniAppSettingsHandler,
|
||||||
|
createMiniAppUpdateMemberStatusHandler,
|
||||||
createMiniAppUpdateMemberRentWeightHandler,
|
createMiniAppUpdateMemberRentWeightHandler,
|
||||||
createMiniAppUpdateSettingsHandler,
|
createMiniAppUpdateSettingsHandler,
|
||||||
createMiniAppUpsertUtilityCategoryHandler
|
createMiniAppUpsertUtilityCategoryHandler
|
||||||
@@ -536,6 +537,15 @@ const server = createBotWebhookServer({
|
|||||||
logger: getLogger('miniapp-admin')
|
logger: getLogger('miniapp-admin')
|
||||||
})
|
})
|
||||||
: undefined,
|
: undefined,
|
||||||
|
miniAppUpdateMemberStatus: householdOnboardingService
|
||||||
|
? createMiniAppUpdateMemberStatusHandler({
|
||||||
|
allowedOrigins: runtime.miniAppAllowedOrigins,
|
||||||
|
botToken: runtime.telegramBotToken,
|
||||||
|
onboardingService: householdOnboardingService,
|
||||||
|
miniAppAdminService: miniAppAdminService!,
|
||||||
|
logger: getLogger('miniapp-admin')
|
||||||
|
})
|
||||||
|
: undefined,
|
||||||
miniAppBillingCycle: householdOnboardingService
|
miniAppBillingCycle: householdOnboardingService
|
||||||
? createMiniAppBillingCycleHandler({
|
? createMiniAppBillingCycleHandler({
|
||||||
allowedOrigins: runtime.miniAppAllowedOrigins,
|
allowedOrigins: runtime.miniAppAllowedOrigins,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
createMiniAppPendingMembersHandler,
|
createMiniAppPendingMembersHandler,
|
||||||
createMiniAppPromoteMemberHandler,
|
createMiniAppPromoteMemberHandler,
|
||||||
createMiniAppSettingsHandler,
|
createMiniAppSettingsHandler,
|
||||||
|
createMiniAppUpdateMemberStatusHandler,
|
||||||
createMiniAppUpdateSettingsHandler
|
createMiniAppUpdateSettingsHandler
|
||||||
} from './miniapp-admin'
|
} from './miniapp-admin'
|
||||||
import { buildMiniAppInitData } from './telegram-miniapp-test-helpers'
|
import { buildMiniAppInitData } from './telegram-miniapp-test-helpers'
|
||||||
@@ -75,6 +76,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -101,6 +103,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: '555777',
|
telegramUserId: '555777',
|
||||||
displayName: 'Mia',
|
displayName: 'Mia',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -118,6 +121,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId,
|
telegramUserId,
|
||||||
displayName: 'Mia',
|
displayName: 'Mia',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: locale,
|
preferredLocale: locale,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -162,6 +166,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId,
|
householdId,
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active' as const,
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -183,11 +188,26 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight,
|
rentShareWeight,
|
||||||
isAdmin: false
|
isAdmin: false
|
||||||
}
|
}
|
||||||
|
: null,
|
||||||
|
updateHouseholdMemberStatus: async (_householdId, memberId, status) =>
|
||||||
|
memberId === 'member-123456'
|
||||||
|
? {
|
||||||
|
id: memberId,
|
||||||
|
householdId: household.householdId,
|
||||||
|
telegramUserId: '123456',
|
||||||
|
displayName: 'Stan',
|
||||||
|
status,
|
||||||
|
preferredLocale: null,
|
||||||
|
householdDefaultLocale: household.defaultLocale,
|
||||||
|
rentShareWeight: 1,
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,6 +222,7 @@ describe('createMiniAppPendingMembersHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -265,6 +286,7 @@ describe('createMiniAppApproveMemberHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -309,6 +331,7 @@ describe('createMiniAppApproveMemberHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '555777',
|
telegramUserId: '555777',
|
||||||
displayName: 'Mia',
|
displayName: 'Mia',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -328,6 +351,7 @@ describe('createMiniAppSettingsHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -340,6 +364,7 @@ describe('createMiniAppSettingsHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -405,6 +430,7 @@ describe('createMiniAppSettingsHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -425,6 +451,7 @@ describe('createMiniAppUpdateSettingsHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -495,6 +522,7 @@ describe('createMiniAppPromoteMemberHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -539,6 +567,7 @@ describe('createMiniAppPromoteMemberHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -547,3 +576,69 @@ describe('createMiniAppPromoteMemberHandler', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('createMiniAppUpdateMemberStatusHandler', () => {
|
||||||
|
test('updates a household member status for an authenticated admin', async () => {
|
||||||
|
const authDate = Math.floor(Date.now() / 1000)
|
||||||
|
const repository = onboardingRepository()
|
||||||
|
repository.listHouseholdMembersByTelegramUserId = async () => [
|
||||||
|
{
|
||||||
|
id: 'member-123456',
|
||||||
|
householdId: 'household-1',
|
||||||
|
telegramUserId: '123456',
|
||||||
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
|
preferredLocale: null,
|
||||||
|
householdDefaultLocale: 'ru',
|
||||||
|
rentShareWeight: 1,
|
||||||
|
isAdmin: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const handler = createMiniAppUpdateMemberStatusHandler({
|
||||||
|
allowedOrigins: ['http://localhost:5173'],
|
||||||
|
botToken: 'test-bot-token',
|
||||||
|
onboardingService: createHouseholdOnboardingService({
|
||||||
|
repository
|
||||||
|
}),
|
||||||
|
miniAppAdminService: createMiniAppAdminService(repository)
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await handler.handler(
|
||||||
|
new Request('http://localhost/api/miniapp/admin/members/status', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
origin: 'http://localhost:5173',
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
initData: buildMiniAppInitData('test-bot-token', authDate, {
|
||||||
|
id: 123456,
|
||||||
|
first_name: 'Stan',
|
||||||
|
username: 'stanislav',
|
||||||
|
language_code: 'ru'
|
||||||
|
}),
|
||||||
|
memberId: 'member-123456',
|
||||||
|
status: 'away'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
expect(await response.json()).toEqual({
|
||||||
|
ok: true,
|
||||||
|
authorized: true,
|
||||||
|
member: {
|
||||||
|
id: 'member-123456',
|
||||||
|
householdId: 'household-1',
|
||||||
|
telegramUserId: '123456',
|
||||||
|
displayName: 'Stan',
|
||||||
|
status: 'away',
|
||||||
|
preferredLocale: null,
|
||||||
|
householdDefaultLocale: 'ru',
|
||||||
|
rentShareWeight: 1,
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import type { HouseholdOnboardingService, MiniAppAdminService } from '@household/application'
|
import type { HouseholdOnboardingService, MiniAppAdminService } from '@household/application'
|
||||||
import type { Logger } from '@household/observability'
|
import type { Logger } from '@household/observability'
|
||||||
import type { HouseholdBillingSettingsRecord } from '@household/ports'
|
import {
|
||||||
|
HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES,
|
||||||
|
type HouseholdBillingSettingsRecord,
|
||||||
|
type HouseholdMemberLifecycleStatus
|
||||||
|
} from '@household/ports'
|
||||||
import type { MiniAppSessionResult } from './miniapp-auth'
|
import type { MiniAppSessionResult } from './miniapp-auth'
|
||||||
import type { AssistantUsageTracker } from './dm-assistant'
|
import type { AssistantUsageTracker } from './dm-assistant'
|
||||||
|
|
||||||
@@ -217,6 +221,42 @@ async function readRentWeightPayload(request: Request): Promise<{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function readMemberStatusPayload(request: Request): Promise<{
|
||||||
|
initData: string
|
||||||
|
memberId: string
|
||||||
|
status: HouseholdMemberLifecycleStatus
|
||||||
|
}> {
|
||||||
|
const clonedRequest = request.clone()
|
||||||
|
const payload = await readMiniAppRequestPayload(request)
|
||||||
|
if (!payload.initData) {
|
||||||
|
throw new Error('Missing initData')
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = await clonedRequest.text()
|
||||||
|
let parsed: { memberId?: string; status?: string }
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(text)
|
||||||
|
} catch {
|
||||||
|
throw new Error('Invalid JSON body')
|
||||||
|
}
|
||||||
|
|
||||||
|
const memberId = parsed.memberId?.trim()
|
||||||
|
const status = parsed.status?.trim().toLowerCase()
|
||||||
|
if (!memberId || !status) {
|
||||||
|
throw new Error('Missing member status fields')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES as readonly string[]).includes(status)) {
|
||||||
|
throw new Error('Invalid member status')
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
initData: payload.initData,
|
||||||
|
memberId,
|
||||||
|
status: status as HouseholdMemberLifecycleStatus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function serializeBillingSettings(settings: HouseholdBillingSettingsRecord) {
|
function serializeBillingSettings(settings: HouseholdBillingSettingsRecord) {
|
||||||
return {
|
return {
|
||||||
householdId: settings.householdId,
|
householdId: settings.householdId,
|
||||||
@@ -253,7 +293,15 @@ async function authenticateAdminSession(
|
|||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (!session.authorized || !session.member) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
|
403,
|
||||||
|
origin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session.member.status !== 'active' || !session.member.isAdmin) {
|
||||||
|
return miniAppJsonResponse(
|
||||||
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
@@ -305,9 +353,14 @@ export function createMiniAppPendingMembersHandler(options: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
@@ -442,9 +495,14 @@ export function createMiniAppUpdateSettingsHandler(options: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
@@ -545,9 +603,14 @@ export function createMiniAppUpsertUtilityCategoryHandler(options: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
@@ -636,9 +699,14 @@ export function createMiniAppPromoteMemberHandler(options: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
@@ -718,9 +786,14 @@ export function createMiniAppUpdateMemberRentWeightHandler(options: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
@@ -769,6 +842,87 @@ export function createMiniAppUpdateMemberRentWeightHandler(options: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createMiniAppUpdateMemberStatusHandler(options: {
|
||||||
|
allowedOrigins: readonly string[]
|
||||||
|
botToken: string
|
||||||
|
onboardingService: HouseholdOnboardingService
|
||||||
|
miniAppAdminService: MiniAppAdminService
|
||||||
|
logger?: Logger
|
||||||
|
}): {
|
||||||
|
handler: (request: Request) => Promise<Response>
|
||||||
|
} {
|
||||||
|
const sessionService = createMiniAppSessionService({
|
||||||
|
botToken: options.botToken,
|
||||||
|
onboardingService: options.onboardingService
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
handler: async (request) => {
|
||||||
|
const origin = allowedMiniAppOrigin(request, options.allowedOrigins)
|
||||||
|
|
||||||
|
if (request.method === 'OPTIONS') {
|
||||||
|
return miniAppJsonResponse({ ok: true }, 204, origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.method !== 'POST') {
|
||||||
|
return miniAppJsonResponse({ ok: false, error: 'Method Not Allowed' }, 405, origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const payload = await readMemberStatusPayload(request)
|
||||||
|
const session = await sessionService.authenticate({
|
||||||
|
initData: payload.initData
|
||||||
|
})
|
||||||
|
|
||||||
|
if (
|
||||||
|
!session ||
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
|
return miniAppJsonResponse(
|
||||||
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
|
session ? 403 : 401,
|
||||||
|
origin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await options.miniAppAdminService.updateMemberStatus({
|
||||||
|
householdId: session.member.householdId,
|
||||||
|
actorIsAdmin: session.member.isAdmin,
|
||||||
|
memberId: payload.memberId,
|
||||||
|
status: payload.status
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.status === 'rejected') {
|
||||||
|
return miniAppJsonResponse(
|
||||||
|
{
|
||||||
|
ok: false,
|
||||||
|
error:
|
||||||
|
result.reason === 'member_not_found' ? 'Member not found' : 'Admin access required'
|
||||||
|
},
|
||||||
|
result.reason === 'member_not_found' ? 404 : 403,
|
||||||
|
origin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return miniAppJsonResponse(
|
||||||
|
{
|
||||||
|
ok: true,
|
||||||
|
authorized: true,
|
||||||
|
member: result.member
|
||||||
|
},
|
||||||
|
200,
|
||||||
|
origin
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
return miniAppErrorResponse(error, origin, options.logger)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function createMiniAppApproveMemberHandler(options: {
|
export function createMiniAppApproveMemberHandler(options: {
|
||||||
allowedOrigins: readonly string[]
|
allowedOrigins: readonly string[]
|
||||||
botToken: string
|
botToken: string
|
||||||
@@ -809,9 +963,14 @@ export function createMiniAppApproveMemberHandler(options: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session.authorized || !session.member) {
|
if (
|
||||||
|
!session.authorized ||
|
||||||
|
!session.member ||
|
||||||
|
session.member.status !== 'active' ||
|
||||||
|
!session.member.isAdmin
|
||||||
|
) {
|
||||||
return miniAppJsonResponse(
|
return miniAppJsonResponse(
|
||||||
{ ok: false, error: 'Access limited to active household members' },
|
{ ok: false, error: 'Admin access required for active household members' },
|
||||||
403,
|
403,
|
||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { describe, expect, test } from 'bun:test'
|
|||||||
import { createHouseholdOnboardingService } from '@household/application'
|
import { createHouseholdOnboardingService } from '@household/application'
|
||||||
import type {
|
import type {
|
||||||
HouseholdConfigurationRepository,
|
HouseholdConfigurationRepository,
|
||||||
|
HouseholdMemberRecord,
|
||||||
HouseholdTopicBindingRecord
|
HouseholdTopicBindingRecord
|
||||||
} from '@household/ports'
|
} from '@household/ports'
|
||||||
|
|
||||||
@@ -19,19 +20,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
defaultLocale: 'ru' as const
|
defaultLocale: 'ru' as const
|
||||||
}
|
}
|
||||||
let joinToken: string | null = 'join-token'
|
let joinToken: string | null = 'join-token'
|
||||||
const members = new Map<
|
const members = new Map<string, HouseholdMemberRecord>()
|
||||||
string,
|
|
||||||
{
|
|
||||||
id: string
|
|
||||||
householdId: string
|
|
||||||
telegramUserId: string
|
|
||||||
displayName: string
|
|
||||||
preferredLocale: 'en' | 'ru' | null
|
|
||||||
householdDefaultLocale: 'en' | 'ru'
|
|
||||||
rentShareWeight: number
|
|
||||||
isAdmin: boolean
|
|
||||||
}
|
|
||||||
>()
|
|
||||||
let pending: {
|
let pending: {
|
||||||
householdId: string
|
householdId: string
|
||||||
householdName: string
|
householdName: string
|
||||||
@@ -97,6 +86,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -118,11 +108,12 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const member = {
|
const member: HouseholdMemberRecord = {
|
||||||
id: `member-${pending.telegramUserId}`,
|
id: `member-${pending.telegramUserId}`,
|
||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: pending.telegramUserId,
|
telegramUserId: pending.telegramUserId,
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -154,6 +145,15 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
},
|
},
|
||||||
|
updateHouseholdMemberStatus: async (_householdId, memberId, status) => {
|
||||||
|
const member = [...members.values()].find((entry) => entry.id === memberId)
|
||||||
|
return member
|
||||||
|
? {
|
||||||
|
...member,
|
||||||
|
status
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
},
|
||||||
getHouseholdBillingSettings: async (householdId) => ({
|
getHouseholdBillingSettings: async (householdId) => ({
|
||||||
householdId,
|
householdId,
|
||||||
settlementCurrency: 'GEL',
|
settlementCurrency: 'GEL',
|
||||||
@@ -232,6 +232,7 @@ describe('createMiniAppAuthHandler', () => {
|
|||||||
authorized: true,
|
authorized: true,
|
||||||
member: {
|
member: {
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru'
|
householdDefaultLocale: 'ru'
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ export interface MiniAppSessionResult {
|
|||||||
id: string
|
id: string
|
||||||
householdId: string
|
householdId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: 'active' | 'away' | 'left'
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
preferredLocale: SupportedLocale | null
|
preferredLocale: SupportedLocale | null
|
||||||
householdDefaultLocale: SupportedLocale
|
householdDefaultLocale: SupportedLocale
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -115,6 +116,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -129,7 +131,8 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
}),
|
}),
|
||||||
updateMemberPreferredLocale: async () => null,
|
updateMemberPreferredLocale: async () => null,
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -225,7 +226,8 @@ function onboardingRepository(): HouseholdConfigurationRepository {
|
|||||||
isActive: input.isActive
|
isActive: input.isActive
|
||||||
}),
|
}),
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,6 +254,7 @@ describe('createMiniAppDashboardHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -354,6 +357,7 @@ describe('createMiniAppDashboardHandler', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -44,6 +45,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: '222222',
|
telegramUserId: '222222',
|
||||||
displayName: 'Mia',
|
displayName: 'Mia',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -93,6 +95,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -161,7 +164,8 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
isActive: input.isActive
|
isActive: input.isActive
|
||||||
}),
|
}),
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,15 @@ describe('createBotWebhookServer', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
miniAppUpdateMemberStatus: {
|
||||||
|
handler: async () =>
|
||||||
|
new Response(JSON.stringify({ ok: true, authorized: true, member: {} }), {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json; charset=utf-8'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
miniAppBillingCycle: {
|
miniAppBillingCycle: {
|
||||||
handler: async () =>
|
handler: async () =>
|
||||||
new Response(JSON.stringify({ ok: true, authorized: true, cycleState: {} }), {
|
new Response(JSON.stringify({ ok: true, authorized: true, cycleState: {} }), {
|
||||||
@@ -347,6 +356,22 @@ describe('createBotWebhookServer', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('accepts mini app member status update request', async () => {
|
||||||
|
const response = await server.fetch(
|
||||||
|
new Request('http://localhost/api/miniapp/admin/members/status', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ initData: 'payload' })
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toBe(200)
|
||||||
|
expect(await response.json()).toEqual({
|
||||||
|
ok: true,
|
||||||
|
authorized: true,
|
||||||
|
member: {}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('accepts mini app billing cycle request', async () => {
|
test('accepts mini app billing cycle request', async () => {
|
||||||
const response = await server.fetch(
|
const response = await server.fetch(
|
||||||
new Request('http://localhost/api/miniapp/admin/billing-cycle', {
|
new Request('http://localhost/api/miniapp/admin/billing-cycle', {
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ export interface BotWebhookServerOptions {
|
|||||||
handler: (request: Request) => Promise<Response>
|
handler: (request: Request) => Promise<Response>
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
|
miniAppUpdateMemberStatus?:
|
||||||
|
| {
|
||||||
|
path?: string
|
||||||
|
handler: (request: Request) => Promise<Response>
|
||||||
|
}
|
||||||
|
| undefined
|
||||||
miniAppBillingCycle?:
|
miniAppBillingCycle?:
|
||||||
| {
|
| {
|
||||||
path?: string
|
path?: string
|
||||||
@@ -186,6 +192,8 @@ export function createBotWebhookServer(options: BotWebhookServerOptions): {
|
|||||||
options.miniAppPromoteMember?.path ?? '/api/miniapp/admin/members/promote'
|
options.miniAppPromoteMember?.path ?? '/api/miniapp/admin/members/promote'
|
||||||
const miniAppUpdateMemberRentWeightPath =
|
const miniAppUpdateMemberRentWeightPath =
|
||||||
options.miniAppUpdateMemberRentWeight?.path ?? '/api/miniapp/admin/members/rent-weight'
|
options.miniAppUpdateMemberRentWeight?.path ?? '/api/miniapp/admin/members/rent-weight'
|
||||||
|
const miniAppUpdateMemberStatusPath =
|
||||||
|
options.miniAppUpdateMemberStatus?.path ?? '/api/miniapp/admin/members/status'
|
||||||
const miniAppBillingCyclePath =
|
const miniAppBillingCyclePath =
|
||||||
options.miniAppBillingCycle?.path ?? '/api/miniapp/admin/billing-cycle'
|
options.miniAppBillingCycle?.path ?? '/api/miniapp/admin/billing-cycle'
|
||||||
const miniAppOpenCyclePath =
|
const miniAppOpenCyclePath =
|
||||||
@@ -268,6 +276,10 @@ export function createBotWebhookServer(options: BotWebhookServerOptions): {
|
|||||||
return await options.miniAppUpdateMemberRentWeight.handler(request)
|
return await options.miniAppUpdateMemberRentWeight.handler(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.miniAppUpdateMemberStatus && url.pathname === miniAppUpdateMemberStatusPath) {
|
||||||
|
return await options.miniAppUpdateMemberStatus.handler(request)
|
||||||
|
}
|
||||||
|
|
||||||
if (options.miniAppBillingCycle && url.pathname === miniAppBillingCyclePath) {
|
if (options.miniAppBillingCycle && url.pathname === miniAppBillingCyclePath) {
|
||||||
return await options.miniAppBillingCycle.handler(request)
|
return await options.miniAppBillingCycle.handler(request)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
joinMiniAppHousehold,
|
joinMiniAppHousehold,
|
||||||
openMiniAppBillingCycle,
|
openMiniAppBillingCycle,
|
||||||
promoteMiniAppMember,
|
promoteMiniAppMember,
|
||||||
|
updateMiniAppMemberStatus,
|
||||||
updateMiniAppMemberRentWeight,
|
updateMiniAppMemberRentWeight,
|
||||||
type MiniAppAdminCycleState,
|
type MiniAppAdminCycleState,
|
||||||
type MiniAppAdminSettingsPayload,
|
type MiniAppAdminSettingsPayload,
|
||||||
@@ -56,6 +57,7 @@ type SessionState =
|
|||||||
member: {
|
member: {
|
||||||
id: string
|
id: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: 'active' | 'away' | 'left'
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
preferredLocale: Locale | null
|
preferredLocale: Locale | null
|
||||||
householdDefaultLocale: Locale
|
householdDefaultLocale: Locale
|
||||||
@@ -95,6 +97,7 @@ const demoSession: Extract<SessionState, { status: 'ready' }> = {
|
|||||||
member: {
|
member: {
|
||||||
id: 'demo-member',
|
id: 'demo-member',
|
||||||
displayName: 'Demo Resident',
|
displayName: 'Demo Resident',
|
||||||
|
status: 'active',
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
preferredLocale: 'en',
|
preferredLocale: 'en',
|
||||||
householdDefaultLocale: 'en'
|
householdDefaultLocale: 'en'
|
||||||
@@ -278,7 +281,11 @@ function App() {
|
|||||||
const [approvingTelegramUserId, setApprovingTelegramUserId] = createSignal<string | null>(null)
|
const [approvingTelegramUserId, setApprovingTelegramUserId] = createSignal<string | null>(null)
|
||||||
const [promotingMemberId, setPromotingMemberId] = createSignal<string | null>(null)
|
const [promotingMemberId, setPromotingMemberId] = createSignal<string | null>(null)
|
||||||
const [savingRentWeightMemberId, setSavingRentWeightMemberId] = createSignal<string | null>(null)
|
const [savingRentWeightMemberId, setSavingRentWeightMemberId] = createSignal<string | null>(null)
|
||||||
|
const [savingMemberStatusId, setSavingMemberStatusId] = createSignal<string | null>(null)
|
||||||
const [rentWeightDrafts, setRentWeightDrafts] = createSignal<Record<string, string>>({})
|
const [rentWeightDrafts, setRentWeightDrafts] = createSignal<Record<string, string>>({})
|
||||||
|
const [memberStatusDrafts, setMemberStatusDrafts] = createSignal<
|
||||||
|
Record<string, 'active' | 'away' | 'left'>
|
||||||
|
>({})
|
||||||
const [savingMemberLocale, setSavingMemberLocale] = createSignal(false)
|
const [savingMemberLocale, setSavingMemberLocale] = createSignal(false)
|
||||||
const [savingHouseholdLocale, setSavingHouseholdLocale] = createSignal(false)
|
const [savingHouseholdLocale, setSavingHouseholdLocale] = createSignal(false)
|
||||||
const [savingBillingSettings, setSavingBillingSettings] = createSignal(false)
|
const [savingBillingSettings, setSavingBillingSettings] = createSignal(false)
|
||||||
@@ -382,6 +389,17 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function memberStatusLabel(status: 'active' | 'away' | 'left'): string {
|
||||||
|
switch (status) {
|
||||||
|
case 'active':
|
||||||
|
return copy().memberStatusActive
|
||||||
|
case 'away':
|
||||||
|
return copy().memberStatusAway
|
||||||
|
case 'left':
|
||||||
|
return copy().memberStatusLeft
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadDashboard(initData: string) {
|
async function loadDashboard(initData: string) {
|
||||||
try {
|
try {
|
||||||
const nextDashboard = await fetchMiniAppDashboard(initData)
|
const nextDashboard = await fetchMiniAppDashboard(initData)
|
||||||
@@ -420,6 +438,9 @@ function App() {
|
|||||||
payload.members.map((member) => [member.id, String(member.rentShareWeight)])
|
payload.members.map((member) => [member.id, String(member.rentShareWeight)])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
setMemberStatusDrafts(
|
||||||
|
Object.fromEntries(payload.members.map((member) => [member.id, member.status]))
|
||||||
|
)
|
||||||
setCycleForm((current) => ({
|
setCycleForm((current) => ({
|
||||||
...current,
|
...current,
|
||||||
rentCurrency: payload.settings.rentCurrency,
|
rentCurrency: payload.settings.rentCurrency,
|
||||||
@@ -1231,6 +1252,35 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSaveMemberStatus(memberId: string) {
|
||||||
|
const initData = webApp?.initData?.trim()
|
||||||
|
const currentReady = readySession()
|
||||||
|
const nextStatus = memberStatusDrafts()[memberId]
|
||||||
|
if (!initData || currentReady?.mode !== 'live' || !currentReady.member.isAdmin || !nextStatus) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setSavingMemberStatusId(memberId)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const member = await updateMiniAppMemberStatus(initData, memberId, nextStatus)
|
||||||
|
setAdminSettings((current) =>
|
||||||
|
current
|
||||||
|
? {
|
||||||
|
...current,
|
||||||
|
members: current.members.map((item) => (item.id === member.id ? member : item))
|
||||||
|
}
|
||||||
|
: current
|
||||||
|
)
|
||||||
|
setMemberStatusDrafts((current) => ({
|
||||||
|
...current,
|
||||||
|
[member.id]: member.status
|
||||||
|
}))
|
||||||
|
} finally {
|
||||||
|
setSavingMemberStatusId(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const renderPanel = () => {
|
const renderPanel = () => {
|
||||||
switch (activeNav()) {
|
switch (activeNav()) {
|
||||||
case 'balances':
|
case 'balances':
|
||||||
@@ -2372,9 +2422,31 @@ function App() {
|
|||||||
<article class="utility-bill-row">
|
<article class="utility-bill-row">
|
||||||
<header>
|
<header>
|
||||||
<strong>{member.displayName}</strong>
|
<strong>{member.displayName}</strong>
|
||||||
<span>{member.isAdmin ? copy().adminTag : copy().residentTag}</span>
|
<span>
|
||||||
|
{member.isAdmin ? copy().adminTag : copy().residentTag}
|
||||||
|
{` · ${memberStatusLabel(member.status)}`}
|
||||||
|
</span>
|
||||||
</header>
|
</header>
|
||||||
<div class="settings-grid">
|
<div class="settings-grid">
|
||||||
|
<label class="settings-field settings-field--wide">
|
||||||
|
<span>{copy().memberStatusLabel}</span>
|
||||||
|
<select
|
||||||
|
value={memberStatusDrafts()[member.id] ?? member.status}
|
||||||
|
onChange={(event) =>
|
||||||
|
setMemberStatusDrafts((current) => ({
|
||||||
|
...current,
|
||||||
|
[member.id]: event.currentTarget.value as
|
||||||
|
| 'active'
|
||||||
|
| 'away'
|
||||||
|
| 'left'
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="active">{copy().memberStatusActive}</option>
|
||||||
|
<option value="away">{copy().memberStatusAway}</option>
|
||||||
|
<option value="left">{copy().memberStatusLeft}</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
<label class="settings-field settings-field--wide">
|
<label class="settings-field settings-field--wide">
|
||||||
<span>{copy().rentWeightLabel}</span>
|
<span>{copy().rentWeightLabel}</span>
|
||||||
<input
|
<input
|
||||||
@@ -2392,6 +2464,16 @@ function App() {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="inline-actions">
|
<div class="inline-actions">
|
||||||
|
<button
|
||||||
|
class="ghost-button"
|
||||||
|
type="button"
|
||||||
|
disabled={savingMemberStatusId() === member.id}
|
||||||
|
onClick={() => void handleSaveMemberStatus(member.id)}
|
||||||
|
>
|
||||||
|
{savingMemberStatusId() === member.id
|
||||||
|
? copy().savingMemberStatus
|
||||||
|
: copy().saveMemberStatusAction}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
class="ghost-button"
|
class="ghost-button"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -2770,6 +2852,11 @@ function App() {
|
|||||||
<span class="pill pill--muted">
|
<span class="pill pill--muted">
|
||||||
{readySession()?.member.isAdmin ? copy().adminTag : copy().residentTag}
|
{readySession()?.member.isAdmin ? copy().adminTag : copy().residentTag}
|
||||||
</span>
|
</span>
|
||||||
|
<span class="pill pill--muted">
|
||||||
|
{readySession()?.member.status
|
||||||
|
? memberStatusLabel(readySession()!.member.status)
|
||||||
|
: copy().memberStatusActive}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
@@ -2802,6 +2889,14 @@ function App() {
|
|||||||
<article class="panel panel--wide">
|
<article class="panel panel--wide">
|
||||||
<p class="eyebrow">{copy().overviewTitle}</p>
|
<p class="eyebrow">{copy().overviewTitle}</p>
|
||||||
<h3>{readySession()?.member.displayName}</h3>
|
<h3>{readySession()?.member.displayName}</h3>
|
||||||
|
<p>
|
||||||
|
{copy().memberStatusSummary.replace(
|
||||||
|
'{status}',
|
||||||
|
readySession()?.member.status
|
||||||
|
? memberStatusLabel(readySession()!.member.status)
|
||||||
|
: copy().memberStatusActive
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
<div>{renderPanel()}</div>
|
<div>{renderPanel()}</div>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -138,6 +138,13 @@ export const dictionary = {
|
|||||||
savingCategory: 'Saving…',
|
savingCategory: 'Saving…',
|
||||||
adminsTitle: 'Admins',
|
adminsTitle: 'Admins',
|
||||||
adminsBody: 'Promote trusted household members so they can manage billing and approvals.',
|
adminsBody: 'Promote trusted household members so they can manage billing and approvals.',
|
||||||
|
memberStatusLabel: 'Member status',
|
||||||
|
saveMemberStatusAction: 'Save status',
|
||||||
|
savingMemberStatus: 'Saving status…',
|
||||||
|
memberStatusActive: 'Active',
|
||||||
|
memberStatusAway: 'Away',
|
||||||
|
memberStatusLeft: 'Left',
|
||||||
|
memberStatusSummary: 'Your household status: {status}.',
|
||||||
rentWeightLabel: 'Rent weight',
|
rentWeightLabel: 'Rent weight',
|
||||||
saveRentWeightAction: 'Save rent weight',
|
saveRentWeightAction: 'Save rent weight',
|
||||||
savingRentWeight: 'Saving weight…',
|
savingRentWeight: 'Saving weight…',
|
||||||
@@ -296,6 +303,13 @@ export const dictionary = {
|
|||||||
adminsTitle: 'Админы',
|
adminsTitle: 'Админы',
|
||||||
adminsBody:
|
adminsBody:
|
||||||
'Повышай доверенных участников, чтобы они могли управлять биллингом и подтверждениями.',
|
'Повышай доверенных участников, чтобы они могли управлять биллингом и подтверждениями.',
|
||||||
|
memberStatusLabel: 'Статус участника',
|
||||||
|
saveMemberStatusAction: 'Сохранить статус',
|
||||||
|
savingMemberStatus: 'Сохраняем статус…',
|
||||||
|
memberStatusActive: 'Активный',
|
||||||
|
memberStatusAway: 'В отъезде',
|
||||||
|
memberStatusLeft: 'Выехал',
|
||||||
|
memberStatusSummary: 'Твой статус в household: {status}.',
|
||||||
rentWeightLabel: 'Вес аренды',
|
rentWeightLabel: 'Вес аренды',
|
||||||
saveRentWeightAction: 'Сохранить вес аренды',
|
saveRentWeightAction: 'Сохранить вес аренды',
|
||||||
savingRentWeight: 'Сохраняем вес…',
|
savingRentWeight: 'Сохраняем вес…',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export interface MiniAppSession {
|
|||||||
id: string
|
id: string
|
||||||
householdId: string
|
householdId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: 'active' | 'away' | 'left'
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
preferredLocale: 'en' | 'ru' | null
|
preferredLocale: 'en' | 'ru' | null
|
||||||
householdDefaultLocale: 'en' | 'ru'
|
householdDefaultLocale: 'en' | 'ru'
|
||||||
@@ -39,6 +40,7 @@ export interface MiniAppPendingMember {
|
|||||||
export interface MiniAppMember {
|
export interface MiniAppMember {
|
||||||
id: string
|
id: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: 'active' | 'away' | 'left'
|
||||||
rentShareWeight: number
|
rentShareWeight: number
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
}
|
}
|
||||||
@@ -514,6 +516,37 @@ export async function updateMiniAppMemberRentWeight(
|
|||||||
return payload.member
|
return payload.member
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateMiniAppMemberStatus(
|
||||||
|
initData: string,
|
||||||
|
memberId: string,
|
||||||
|
status: 'active' | 'away' | 'left'
|
||||||
|
): Promise<MiniAppMember> {
|
||||||
|
const response = await fetch(`${apiBaseUrl()}/api/miniapp/admin/members/status`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
initData,
|
||||||
|
memberId,
|
||||||
|
status
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const payload = (await response.json()) as {
|
||||||
|
ok: boolean
|
||||||
|
authorized?: boolean
|
||||||
|
member?: MiniAppMember
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok || !payload.member) {
|
||||||
|
throw new Error(payload.error ?? 'Failed to update member status')
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload.member
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchMiniAppBillingCycle(initData: string): Promise<MiniAppAdminCycleState> {
|
export async function fetchMiniAppBillingCycle(initData: string): Promise<MiniAppAdminCycleState> {
|
||||||
const response = await fetch(`${apiBaseUrl()}/api/miniapp/admin/billing-cycle`, {
|
const response = await fetch(`${apiBaseUrl()}/api/miniapp/admin/billing-cycle`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ import {
|
|||||||
type CurrencyCode
|
type CurrencyCode
|
||||||
} from '@household/domain'
|
} from '@household/domain'
|
||||||
import {
|
import {
|
||||||
|
HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES,
|
||||||
HOUSEHOLD_TOPIC_ROLES,
|
HOUSEHOLD_TOPIC_ROLES,
|
||||||
type HouseholdBillingSettingsRecord,
|
type HouseholdBillingSettingsRecord,
|
||||||
type HouseholdConfigurationRepository,
|
type HouseholdConfigurationRepository,
|
||||||
type HouseholdJoinTokenRecord,
|
type HouseholdJoinTokenRecord,
|
||||||
|
type HouseholdMemberLifecycleStatus,
|
||||||
type HouseholdMemberRecord,
|
type HouseholdMemberRecord,
|
||||||
type HouseholdPendingMemberRecord,
|
type HouseholdPendingMemberRecord,
|
||||||
type HouseholdTelegramChatRecord,
|
type HouseholdTelegramChatRecord,
|
||||||
@@ -32,6 +34,16 @@ function normalizeTopicRole(role: string): HouseholdTopicRole {
|
|||||||
throw new Error(`Unsupported household topic role: ${role}`)
|
throw new Error(`Unsupported household topic role: ${role}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeMemberLifecycleStatus(raw: string): HouseholdMemberLifecycleStatus {
|
||||||
|
const normalized = raw.trim().toLowerCase()
|
||||||
|
|
||||||
|
if ((HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES as readonly string[]).includes(normalized)) {
|
||||||
|
return normalized as HouseholdMemberLifecycleStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Unsupported household member lifecycle status: ${raw}`)
|
||||||
|
}
|
||||||
|
|
||||||
function toHouseholdTelegramChatRecord(row: {
|
function toHouseholdTelegramChatRecord(row: {
|
||||||
householdId: string
|
householdId: string
|
||||||
householdName: string
|
householdName: string
|
||||||
@@ -113,6 +125,7 @@ function toHouseholdMemberRecord(row: {
|
|||||||
householdId: string
|
householdId: string
|
||||||
telegramUserId: string
|
telegramUserId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
lifecycleStatus: string
|
||||||
preferredLocale: string | null
|
preferredLocale: string | null
|
||||||
defaultLocale: string
|
defaultLocale: string
|
||||||
rentShareWeight: number
|
rentShareWeight: number
|
||||||
@@ -128,6 +141,7 @@ function toHouseholdMemberRecord(row: {
|
|||||||
householdId: row.householdId,
|
householdId: row.householdId,
|
||||||
telegramUserId: row.telegramUserId,
|
telegramUserId: row.telegramUserId,
|
||||||
displayName: row.displayName,
|
displayName: row.displayName,
|
||||||
|
status: normalizeMemberLifecycleStatus(row.lifecycleStatus),
|
||||||
preferredLocale: normalizeSupportedLocale(row.preferredLocale),
|
preferredLocale: normalizeSupportedLocale(row.preferredLocale),
|
||||||
householdDefaultLocale,
|
householdDefaultLocale,
|
||||||
rentShareWeight: row.rentShareWeight,
|
rentShareWeight: row.rentShareWeight,
|
||||||
@@ -775,6 +789,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
lifecycleStatus: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
rentShareWeight: input.rentShareWeight ?? 1,
|
rentShareWeight: input.rentShareWeight ?? 1,
|
||||||
isAdmin: input.isAdmin ? 1 : 0
|
isAdmin: input.isAdmin ? 1 : 0
|
||||||
@@ -783,6 +798,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
target: [schema.members.householdId, schema.members.telegramUserId],
|
target: [schema.members.householdId, schema.members.telegramUserId],
|
||||||
set: {
|
set: {
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
lifecycleStatus: input.status ?? schema.members.lifecycleStatus,
|
||||||
preferredLocale: input.preferredLocale ?? schema.members.preferredLocale,
|
preferredLocale: input.preferredLocale ?? schema.members.preferredLocale,
|
||||||
rentShareWeight: input.rentShareWeight ?? schema.members.rentShareWeight,
|
rentShareWeight: input.rentShareWeight ?? schema.members.rentShareWeight,
|
||||||
...(input.isAdmin
|
...(input.isAdmin
|
||||||
@@ -797,6 +813,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
isAdmin: schema.members.isAdmin
|
isAdmin: schema.members.isAdmin
|
||||||
@@ -825,6 +842,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
defaultLocale: schema.households.defaultLocale,
|
defaultLocale: schema.households.defaultLocale,
|
||||||
@@ -851,6 +869,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
defaultLocale: schema.households.defaultLocale,
|
defaultLocale: schema.households.defaultLocale,
|
||||||
@@ -1033,6 +1052,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
defaultLocale: schema.households.defaultLocale,
|
defaultLocale: schema.households.defaultLocale,
|
||||||
@@ -1104,6 +1124,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: pending.householdId,
|
householdId: pending.householdId,
|
||||||
telegramUserId: pending.telegramUserId,
|
telegramUserId: pending.telegramUserId,
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
lifecycleStatus: 'active',
|
||||||
preferredLocale: normalizeSupportedLocale(pending.languageCode),
|
preferredLocale: normalizeSupportedLocale(pending.languageCode),
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
isAdmin: input.isAdmin ? 1 : 0
|
isAdmin: input.isAdmin ? 1 : 0
|
||||||
@@ -1112,6 +1133,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
target: [schema.members.householdId, schema.members.telegramUserId],
|
target: [schema.members.householdId, schema.members.telegramUserId],
|
||||||
set: {
|
set: {
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
lifecycleStatus: 'active',
|
||||||
preferredLocale:
|
preferredLocale:
|
||||||
normalizeSupportedLocale(pending.languageCode) ?? schema.members.preferredLocale,
|
normalizeSupportedLocale(pending.languageCode) ?? schema.members.preferredLocale,
|
||||||
...(input.isAdmin
|
...(input.isAdmin
|
||||||
@@ -1126,6 +1148,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
isAdmin: schema.members.isAdmin
|
isAdmin: schema.members.isAdmin
|
||||||
@@ -1198,6 +1221,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
isAdmin: schema.members.isAdmin
|
isAdmin: schema.members.isAdmin
|
||||||
@@ -1231,6 +1255,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
isAdmin: schema.members.isAdmin
|
isAdmin: schema.members.isAdmin
|
||||||
@@ -1264,6 +1289,7 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
householdId: schema.members.householdId,
|
householdId: schema.members.householdId,
|
||||||
telegramUserId: schema.members.telegramUserId,
|
telegramUserId: schema.members.telegramUserId,
|
||||||
displayName: schema.members.displayName,
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
preferredLocale: schema.members.preferredLocale,
|
preferredLocale: schema.members.preferredLocale,
|
||||||
rentShareWeight: schema.members.rentShareWeight,
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
isAdmin: schema.members.isAdmin
|
isAdmin: schema.members.isAdmin
|
||||||
@@ -1279,6 +1305,40 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
|
|||||||
throw new Error('Failed to resolve household chat after rent weight update')
|
throw new Error('Failed to resolve household chat after rent weight update')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return toHouseholdMemberRecord({
|
||||||
|
...row,
|
||||||
|
defaultLocale: household.defaultLocale
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateHouseholdMemberStatus(householdId, memberId, status) {
|
||||||
|
const rows = await db
|
||||||
|
.update(schema.members)
|
||||||
|
.set({
|
||||||
|
lifecycleStatus: status
|
||||||
|
})
|
||||||
|
.where(and(eq(schema.members.householdId, householdId), eq(schema.members.id, memberId)))
|
||||||
|
.returning({
|
||||||
|
id: schema.members.id,
|
||||||
|
householdId: schema.members.householdId,
|
||||||
|
telegramUserId: schema.members.telegramUserId,
|
||||||
|
displayName: schema.members.displayName,
|
||||||
|
lifecycleStatus: schema.members.lifecycleStatus,
|
||||||
|
preferredLocale: schema.members.preferredLocale,
|
||||||
|
rentShareWeight: schema.members.rentShareWeight,
|
||||||
|
isAdmin: schema.members.isAdmin
|
||||||
|
})
|
||||||
|
|
||||||
|
const row = rows[0]
|
||||||
|
if (!row) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const household = await this.getHouseholdChatByHouseholdId(householdId)
|
||||||
|
if (!household) {
|
||||||
|
throw new Error('Failed to resolve household chat after member status update')
|
||||||
|
}
|
||||||
|
|
||||||
return toHouseholdMemberRecord({
|
return toHouseholdMemberRecord({
|
||||||
...row,
|
...row,
|
||||||
defaultLocale: household.defaultLocale
|
defaultLocale: household.defaultLocale
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ function createRepositoryStub() {
|
|||||||
householdId: household.householdId,
|
householdId: household.householdId,
|
||||||
telegramUserId: '1',
|
telegramUserId: '1',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -94,6 +95,7 @@ function createRepositoryStub() {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -121,6 +123,7 @@ function createRepositoryStub() {
|
|||||||
householdId: pending.householdId,
|
householdId: pending.householdId,
|
||||||
telegramUserId: pending.telegramUserId,
|
telegramUserId: pending.telegramUserId,
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -174,7 +177,8 @@ function createRepositoryStub() {
|
|||||||
isActive: input.isActive
|
isActive: input.isActive
|
||||||
}),
|
}),
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -243,6 +247,7 @@ describe('createHouseholdAdminService', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '2',
|
telegramUserId: '2',
|
||||||
displayName: 'Alice',
|
displayName: 'Alice',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ function createRepositoryStub() {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -133,6 +134,7 @@ function createRepositoryStub() {
|
|||||||
householdId: pending.householdId,
|
householdId: pending.householdId,
|
||||||
telegramUserId: pending.telegramUserId,
|
telegramUserId: pending.telegramUserId,
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: household.defaultLocale,
|
householdDefaultLocale: household.defaultLocale,
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -198,6 +200,9 @@ function createRepositoryStub() {
|
|||||||
},
|
},
|
||||||
async updateHouseholdMemberRentShareWeight() {
|
async updateHouseholdMemberRentShareWeight() {
|
||||||
return null
|
return null
|
||||||
|
},
|
||||||
|
async updateHouseholdMemberStatus() {
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,6 +330,7 @@ describe('createHouseholdOnboardingService', () => {
|
|||||||
id: 'member-42',
|
id: 'member-42',
|
||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -340,6 +346,7 @@ describe('createHouseholdOnboardingService', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '42',
|
telegramUserId: '42',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -358,6 +365,7 @@ describe('createHouseholdOnboardingService', () => {
|
|||||||
householdId: 'household-2',
|
householdId: 'household-2',
|
||||||
telegramUserId: '42',
|
telegramUserId: '42',
|
||||||
displayName: 'Stan elsewhere',
|
displayName: 'Stan elsewhere',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export type HouseholdMiniAppAccess =
|
|||||||
id: string
|
id: string
|
||||||
householdId: string
|
householdId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: HouseholdMemberRecord['status']
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
preferredLocale: SupportedLocale | null
|
preferredLocale: SupportedLocale | null
|
||||||
householdDefaultLocale: SupportedLocale
|
householdDefaultLocale: SupportedLocale
|
||||||
@@ -68,6 +69,7 @@ export interface HouseholdOnboardingService {
|
|||||||
id: string
|
id: string
|
||||||
householdId: string
|
householdId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: HouseholdMemberRecord['status']
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
preferredLocale: SupportedLocale | null
|
preferredLocale: SupportedLocale | null
|
||||||
householdDefaultLocale: SupportedLocale
|
householdDefaultLocale: SupportedLocale
|
||||||
@@ -84,6 +86,7 @@ function toMember(member: HouseholdMemberRecord): {
|
|||||||
id: string
|
id: string
|
||||||
householdId: string
|
householdId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: HouseholdMemberRecord['status']
|
||||||
isAdmin: boolean
|
isAdmin: boolean
|
||||||
preferredLocale: SupportedLocale | null
|
preferredLocale: SupportedLocale | null
|
||||||
householdDefaultLocale: SupportedLocale
|
householdDefaultLocale: SupportedLocale
|
||||||
@@ -93,6 +96,7 @@ function toMember(member: HouseholdMemberRecord): {
|
|||||||
id: member.id,
|
id: member.id,
|
||||||
householdId: member.householdId,
|
householdId: member.householdId,
|
||||||
displayName: member.displayName,
|
displayName: member.displayName,
|
||||||
|
status: member.status,
|
||||||
isAdmin: member.isAdmin,
|
isAdmin: member.isAdmin,
|
||||||
preferredLocale: member.preferredLocale,
|
preferredLocale: member.preferredLocale,
|
||||||
householdDefaultLocale: member.householdDefaultLocale,
|
householdDefaultLocale: member.householdDefaultLocale,
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ function createRepositoryStub() {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? existing?.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? existing?.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? existing?.preferredLocale ?? null,
|
||||||
householdDefaultLocale:
|
householdDefaultLocale:
|
||||||
[...households.values()].find((household) => household.householdId === input.householdId)
|
[...households.values()].find((household) => household.householdId === input.householdId)
|
||||||
@@ -215,6 +216,7 @@ function createRepositoryStub() {
|
|||||||
householdId: pending.householdId,
|
householdId: pending.householdId,
|
||||||
telegramUserId: pending.telegramUserId,
|
telegramUserId: pending.telegramUserId,
|
||||||
displayName: pending.displayName,
|
displayName: pending.displayName,
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale:
|
householdDefaultLocale:
|
||||||
[...households.values()].find(
|
[...households.values()].find(
|
||||||
@@ -319,6 +321,22 @@ function createRepositoryStub() {
|
|||||||
}
|
}
|
||||||
members.set(`${householdId}:${member.telegramUserId}`, next)
|
members.set(`${householdId}:${member.telegramUserId}`, next)
|
||||||
return next
|
return next
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateHouseholdMemberStatus(householdId, memberId, status) {
|
||||||
|
const member = [...members.values()].find(
|
||||||
|
(entry) => entry.householdId === householdId && entry.id === memberId
|
||||||
|
)
|
||||||
|
if (!member) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = {
|
||||||
|
...member,
|
||||||
|
status
|
||||||
|
}
|
||||||
|
members.set(`${householdId}:${member.telegramUserId}`, next)
|
||||||
|
return next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,6 +371,7 @@ describe('createHouseholdSetupService', () => {
|
|||||||
householdId: result.household.householdId,
|
householdId: result.household.householdId,
|
||||||
telegramUserId: '42',
|
telegramUserId: '42',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -391,6 +410,7 @@ describe('createHouseholdSetupService', () => {
|
|||||||
householdId: result.household.householdId,
|
householdId: result.household.householdId,
|
||||||
telegramUserId: '77',
|
telegramUserId: '77',
|
||||||
displayName: 'Mia',
|
displayName: 'Mia',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function createRepository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -109,7 +110,8 @@ function createRepository(): HouseholdConfigurationRepository {
|
|||||||
isActive: input.isActive
|
isActive: input.isActive
|
||||||
}),
|
}),
|
||||||
promoteHouseholdAdmin: async () => null,
|
promoteHouseholdAdmin: async () => null,
|
||||||
updateHouseholdMemberRentShareWeight: async () => null
|
updateHouseholdMemberRentShareWeight: async () => null,
|
||||||
|
updateHouseholdMemberStatus: async () => null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: input.displayName,
|
displayName: input.displayName,
|
||||||
|
status: input.status ?? 'active',
|
||||||
preferredLocale: input.preferredLocale ?? null,
|
preferredLocale: input.preferredLocale ?? null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -87,6 +88,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: input.householdId,
|
householdId: input.householdId,
|
||||||
telegramUserId: input.telegramUserId,
|
telegramUserId: input.telegramUserId,
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -108,6 +110,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId,
|
telegramUserId,
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: locale,
|
preferredLocale: locale,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -152,6 +155,7 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId,
|
householdId,
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -165,11 +169,26 @@ function repository(): HouseholdConfigurationRepository {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight,
|
rentShareWeight,
|
||||||
isAdmin: false
|
isAdmin: false
|
||||||
}
|
}
|
||||||
|
: null,
|
||||||
|
updateHouseholdMemberStatus: async (_householdId, memberId, status) =>
|
||||||
|
memberId === 'member-123456'
|
||||||
|
? {
|
||||||
|
id: memberId,
|
||||||
|
householdId: 'household-1',
|
||||||
|
telegramUserId: '123456',
|
||||||
|
displayName: 'Stan',
|
||||||
|
status,
|
||||||
|
preferredLocale: null,
|
||||||
|
householdDefaultLocale: 'ru',
|
||||||
|
rentShareWeight: 1,
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,6 +337,7 @@ describe('createMiniAppAdminService', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -342,6 +362,7 @@ describe('createMiniAppAdminService', () => {
|
|||||||
householdId: 'household-1',
|
householdId: 'household-1',
|
||||||
telegramUserId: '123456',
|
telegramUserId: '123456',
|
||||||
displayName: 'Stan',
|
displayName: 'Stan',
|
||||||
|
status: 'active',
|
||||||
preferredLocale: null,
|
preferredLocale: null,
|
||||||
householdDefaultLocale: 'ru',
|
householdDefaultLocale: 'ru',
|
||||||
rentShareWeight: 1,
|
rentShareWeight: 1,
|
||||||
@@ -349,4 +370,30 @@ describe('createMiniAppAdminService', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('updates a household member lifecycle status for admins', async () => {
|
||||||
|
const service = createMiniAppAdminService(repository())
|
||||||
|
|
||||||
|
const result = await service.updateMemberStatus({
|
||||||
|
householdId: 'household-1',
|
||||||
|
actorIsAdmin: true,
|
||||||
|
memberId: 'member-123456',
|
||||||
|
status: 'away'
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
status: 'ok',
|
||||||
|
member: {
|
||||||
|
id: 'member-123456',
|
||||||
|
householdId: 'household-1',
|
||||||
|
telegramUserId: '123456',
|
||||||
|
displayName: 'Stan',
|
||||||
|
status: 'away',
|
||||||
|
preferredLocale: null,
|
||||||
|
householdDefaultLocale: 'ru',
|
||||||
|
rentShareWeight: 1,
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type {
|
import type {
|
||||||
HouseholdBillingSettingsRecord,
|
HouseholdBillingSettingsRecord,
|
||||||
HouseholdConfigurationRepository,
|
HouseholdConfigurationRepository,
|
||||||
|
HouseholdMemberLifecycleStatus,
|
||||||
HouseholdMemberRecord,
|
HouseholdMemberRecord,
|
||||||
HouseholdPendingMemberRecord,
|
HouseholdPendingMemberRecord,
|
||||||
HouseholdTopicBindingRecord,
|
HouseholdTopicBindingRecord,
|
||||||
@@ -126,6 +127,21 @@ export interface MiniAppAdminService {
|
|||||||
reason: 'not_admin' | 'invalid_weight' | 'member_not_found'
|
reason: 'not_admin' | 'invalid_weight' | 'member_not_found'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
updateMemberStatus(input: {
|
||||||
|
householdId: string
|
||||||
|
actorIsAdmin: boolean
|
||||||
|
memberId: string
|
||||||
|
status: HouseholdMemberLifecycleStatus
|
||||||
|
}): Promise<
|
||||||
|
| {
|
||||||
|
status: 'ok'
|
||||||
|
member: HouseholdMemberRecord
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
status: 'rejected'
|
||||||
|
reason: 'not_admin' | 'member_not_found'
|
||||||
|
}
|
||||||
|
>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createMiniAppAdminService(
|
export function createMiniAppAdminService(
|
||||||
@@ -349,6 +365,32 @@ export function createMiniAppAdminService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: 'ok',
|
||||||
|
member
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateMemberStatus(input) {
|
||||||
|
if (!input.actorIsAdmin) {
|
||||||
|
return {
|
||||||
|
status: 'rejected',
|
||||||
|
reason: 'not_admin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const member = await repository.updateHouseholdMemberStatus(
|
||||||
|
input.householdId,
|
||||||
|
input.memberId,
|
||||||
|
input.status
|
||||||
|
)
|
||||||
|
if (!member) {
|
||||||
|
return {
|
||||||
|
status: 'rejected',
|
||||||
|
reason: 'member_not_found'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
member
|
member
|
||||||
|
|||||||
1
packages/db/drizzle/0014_empty_risque.sql
Normal file
1
packages/db/drizzle/0014_empty_risque.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "members" ADD COLUMN "lifecycle_status" text DEFAULT 'active' NOT NULL;
|
||||||
2952
packages/db/drizzle/meta/0014_snapshot.json
Normal file
2952
packages/db/drizzle/meta/0014_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -99,6 +99,13 @@
|
|||||||
"when": 1773147481265,
|
"when": 1773147481265,
|
||||||
"tag": "0013_wild_avengers",
|
"tag": "0013_wild_avengers",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 14,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1773222186943,
|
||||||
|
"tag": "0014_empty_risque",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ export const members = pgTable(
|
|||||||
.references(() => households.id, { onDelete: 'cascade' }),
|
.references(() => households.id, { onDelete: 'cascade' }),
|
||||||
telegramUserId: text('telegram_user_id').notNull(),
|
telegramUserId: text('telegram_user_id').notNull(),
|
||||||
displayName: text('display_name').notNull(),
|
displayName: text('display_name').notNull(),
|
||||||
|
lifecycleStatus: text('lifecycle_status').default('active').notNull(),
|
||||||
preferredLocale: text('preferred_locale'),
|
preferredLocale: text('preferred_locale'),
|
||||||
rentShareWeight: integer('rent_share_weight').default(1).notNull(),
|
rentShareWeight: integer('rent_share_weight').default(1).notNull(),
|
||||||
isAdmin: integer('is_admin').default(0).notNull(),
|
isAdmin: integer('is_admin').default(0).notNull(),
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ import type { CurrencyCode, SupportedLocale } from '@household/domain'
|
|||||||
import type { ReminderTarget } from './reminders'
|
import type { ReminderTarget } from './reminders'
|
||||||
|
|
||||||
export const HOUSEHOLD_TOPIC_ROLES = ['purchase', 'feedback', 'reminders', 'payments'] as const
|
export const HOUSEHOLD_TOPIC_ROLES = ['purchase', 'feedback', 'reminders', 'payments'] as const
|
||||||
|
export const HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES = ['active', 'away', 'left'] as const
|
||||||
|
|
||||||
export type HouseholdTopicRole = (typeof HOUSEHOLD_TOPIC_ROLES)[number]
|
export type HouseholdTopicRole = (typeof HOUSEHOLD_TOPIC_ROLES)[number]
|
||||||
|
export type HouseholdMemberLifecycleStatus = (typeof HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES)[number]
|
||||||
|
|
||||||
export interface HouseholdTelegramChatRecord {
|
export interface HouseholdTelegramChatRecord {
|
||||||
householdId: string
|
householdId: string
|
||||||
@@ -43,6 +45,7 @@ export interface HouseholdMemberRecord {
|
|||||||
householdId: string
|
householdId: string
|
||||||
telegramUserId: string
|
telegramUserId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status: HouseholdMemberLifecycleStatus
|
||||||
preferredLocale: SupportedLocale | null
|
preferredLocale: SupportedLocale | null
|
||||||
householdDefaultLocale: SupportedLocale
|
householdDefaultLocale: SupportedLocale
|
||||||
rentShareWeight: number
|
rentShareWeight: number
|
||||||
@@ -130,6 +133,7 @@ export interface HouseholdConfigurationRepository {
|
|||||||
householdId: string
|
householdId: string
|
||||||
telegramUserId: string
|
telegramUserId: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
status?: HouseholdMemberLifecycleStatus
|
||||||
preferredLocale?: SupportedLocale | null
|
preferredLocale?: SupportedLocale | null
|
||||||
rentShareWeight?: number
|
rentShareWeight?: number
|
||||||
isAdmin?: boolean
|
isAdmin?: boolean
|
||||||
@@ -188,4 +192,9 @@ export interface HouseholdConfigurationRepository {
|
|||||||
memberId: string,
|
memberId: string,
|
||||||
rentShareWeight: number
|
rentShareWeight: number
|
||||||
): Promise<HouseholdMemberRecord | null>
|
): Promise<HouseholdMemberRecord | null>
|
||||||
|
updateHouseholdMemberStatus(
|
||||||
|
householdId: string,
|
||||||
|
memberId: string,
|
||||||
|
status: HouseholdMemberLifecycleStatus
|
||||||
|
): Promise<HouseholdMemberRecord | null>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ export type {
|
|||||||
ReleaseProcessedBotMessageInput
|
ReleaseProcessedBotMessageInput
|
||||||
} from './processed-bot-messages'
|
} from './processed-bot-messages'
|
||||||
export {
|
export {
|
||||||
|
HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES,
|
||||||
HOUSEHOLD_TOPIC_ROLES,
|
HOUSEHOLD_TOPIC_ROLES,
|
||||||
type HouseholdConfigurationRepository,
|
type HouseholdConfigurationRepository,
|
||||||
type HouseholdBillingSettingsRecord,
|
type HouseholdBillingSettingsRecord,
|
||||||
type HouseholdJoinTokenRecord,
|
type HouseholdJoinTokenRecord,
|
||||||
|
type HouseholdMemberLifecycleStatus,
|
||||||
type HouseholdMemberRecord,
|
type HouseholdMemberRecord,
|
||||||
type HouseholdPendingMemberRecord,
|
type HouseholdPendingMemberRecord,
|
||||||
type HouseholdTelegramChatRecord,
|
type HouseholdTelegramChatRecord,
|
||||||
|
|||||||
Reference in New Issue
Block a user