fix(subscriptions): atomic UsageRecord metering to prevent quota bypass
- Add @@unique([subscriptionId, metric, periodStart, periodEnd]) constraint to UsageRecord model with corresponding migration - Replace racy findFirst+update/create pattern with Prisma upsert using INSERT ON CONFLICT DO UPDATE SET count = count + delta - Fix CheckQuotaHandler to use period-scoped findUnique instead of unscoped findFirst, preventing stale cross-period reads - Update tests to reflect atomic upsert pattern Closes GOO-4 Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
70
apps/web/lib/vietnam-geo.ts
Normal file
70
apps/web/lib/vietnam-geo.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* vietnam-geo.ts
|
||||
* Centralized Vietnamese administrative geography data.
|
||||
*
|
||||
* NOTE: As of 01/01/2021, Quận 2, Quận 9 and the old Thủ Đức district were
|
||||
* merged into Thành phố Thủ Đức. Use HCM_DISTRICTS for all district-picker UIs.
|
||||
*/
|
||||
|
||||
/** Current Ho Chi Minh City districts / city-level subdivisions (post-2021). */
|
||||
export const HCM_DISTRICTS: readonly string[] = [
|
||||
// Inner urban districts (quận nội thành)
|
||||
'Quận 1',
|
||||
'Quận 3',
|
||||
'Quận 4',
|
||||
'Quận 5',
|
||||
'Quận 6',
|
||||
'Quận 7',
|
||||
'Quận 8',
|
||||
'Quận 10',
|
||||
'Quận 11',
|
||||
'Quận 12',
|
||||
// Thu Duc city (merged from former Quận 2, Quận 9, and Thủ Đức district)
|
||||
'Thành phố Thủ Đức',
|
||||
// Suburban districts (quận ngoại thành)
|
||||
'Bình Tân',
|
||||
'Bình Thạnh',
|
||||
'Gò Vấp',
|
||||
'Phú Nhuận',
|
||||
'Tân Bình',
|
||||
'Tân Phú',
|
||||
// Rural districts (huyện)
|
||||
'Bình Chánh',
|
||||
'Cần Giờ',
|
||||
'Củ Chi',
|
||||
'Hóc Môn',
|
||||
'Nhà Bè',
|
||||
] as const;
|
||||
|
||||
/** Major Vietnamese provinces / centrally-administered municipalities. */
|
||||
export const PROVINCES: readonly string[] = [
|
||||
'Hồ Chí Minh',
|
||||
'Hà Nội',
|
||||
'Đà Nẵng',
|
||||
'Bình Dương',
|
||||
'Đồng Nai',
|
||||
'Long An',
|
||||
'Bà Rịa - Vũng Tàu',
|
||||
'Bắc Ninh',
|
||||
'Hải Phòng',
|
||||
'Hải Dương',
|
||||
'Hưng Yên',
|
||||
'Quảng Ninh',
|
||||
'Thái Nguyên',
|
||||
'Vĩnh Phúc',
|
||||
'Cần Thơ',
|
||||
] as const;
|
||||
|
||||
/** Major cities shown in city pickers across the platform. */
|
||||
export const MAJOR_CITIES: readonly string[] = [
|
||||
'Hồ Chí Minh',
|
||||
'Hà Nội',
|
||||
'Đà Nẵng',
|
||||
'Nha Trang',
|
||||
'Cần Thơ',
|
||||
'Hải Phòng',
|
||||
'Bình Dương',
|
||||
'Đồng Nai',
|
||||
'Long An',
|
||||
'Bà Rịa - Vũng Tàu',
|
||||
] as const;
|
||||
Reference in New Issue
Block a user