Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

added an endpoint that returns IP specific country & currency data

Blue Mouse8c020d4e670e
diff --git a/apps/production/src/user/user.controller.ts b/apps/production/src/user/user.controller.ts
index ef5b272d2..67496fd9d 100644
--- a/apps/production/src/user/user.controller.ts
+++ b/apps/production/src/user/user.controller.ts
@@ -31,6 +31,8 @@ import { v4 as uuidv4 } from 'uuid'
import { Markup } from 'telegraf'
import { JwtAccessTokenGuard } from '../auth/guards'
+
+import { Public, Roles, CurrentUserId } from '../auth/decorators'
import { TelegramService } from '../integrations/telegram/telegram.service'
import { UserService } from './user.service'
import { ProjectService, deleteProjectRedis } from '../project/project.service'
@@ -41,7 +43,6 @@ import {
PlanCode,
Theme,
} from './entities/user.entity'
-import { Roles } from '../auth/decorators/roles.decorator'
import { Pagination } from '../common/pagination/pagination'
import {
GDPR_EXPORT_TIMEFRAME,
@@ -52,7 +53,6 @@ import {
import { RolesGuard } from '../auth/guards/roles.guard'
import { UpdateUserProfileDTO } from './dto/update-user.dto'
import { AdminUpdateUserProfileDTO } from './dto/admin-update-user.dto'
-import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'
import { ActionTokensService } from '../action-tokens/action-tokens.service'
import { MailerService } from '../mailer/mailer.service'
import { ActionTokenType } from '../action-tokens/action-token.entity'
@@ -614,4 +614,17 @@ export class UserController {
return user
}
+
+ @Get('metainfo')
+ @Public()
+ async getMetaInfo(
+ @Headers() headers,
+ ): Promise<any> {
+ const country = headers['cf-ipcountry'] || 'XX'
+
+ return {
+ country,
+ ...this.userService.getCurrencyByCountry(country),
+ }
+ }
}
diff --git a/apps/production/src/user/user.service.ts b/apps/production/src/user/user.service.ts
index dc22d550d..cdff6612c 100644
--- a/apps/production/src/user/user.service.ts
+++ b/apps/production/src/user/user.service.ts
@@ -14,6 +14,53 @@ import { RefreshToken } from './entities/refresh-token.entity'
import { UserGoogleDTO } from './dto/user-google.dto'
import { UserGithubDTO } from './dto/user-github.dto'
+const EUR = {
+ symbol: '€',
+ code: 'EUR',
+}
+
+const USD = {
+ symbol: '$',
+ code: 'USD',
+}
+
+const GBP = {
+ symbol: '£',
+ code: 'GBP',
+}
+
+const CURRENCY_BY_COUNTRY = {
+ AT: EUR, // Austria
+ BE: EUR, // Belgium
+ BG: EUR, // Bulgaria
+ CY: EUR, // Cyprus
+ CZ: EUR, // Czech Republic
+ DE: EUR, // Germany
+ DK: EUR, // Denmark
+ EE: EUR, // Estonia
+ ES: EUR, // Spain
+ FI: EUR, // Finland
+ FR: EUR, // France
+ GB: GBP, // United Kingdom
+ GR: EUR, // Greece
+ HR: EUR, // Croatia
+ HU: EUR, // Hungary
+ IE: EUR, // Ireland
+ IT: EUR, // Italy
+ LT: EUR, // Lithuania
+ LU: EUR, // Luxembourg
+ LV: EUR, // Latvia
+ MT: EUR, // Malta
+ NL: EUR, // Netherlands
+ PL: EUR, // Poland
+ PT: EUR, // Portugal
+ RO: EUR, // Romania
+ SE: EUR, // Sweden
+ SI: EUR, // Slovenia
+ SK: EUR, // Slovakia
+ US: USD, // United States
+}
+
@Injectable()
export class UserService {
constructor(
@@ -236,4 +283,8 @@ export class UserService {
isTelegramChatIdConfirmed,
})
}
+
+ getCurrencyByCountry(country: string) {
+ return CURRENCY_BY_COUNTRY[country] || USD
+ }
}