-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a371048
commit cd1d91d
Showing
6 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
input UpdateLanguageInput { | ||
lang: String! | ||
} | ||
|
||
type Mutation { | ||
updateLanguage(input: UpdateLanguageInput!): String! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SettingsService } from './settings.service'; | ||
import { SettingsResolver } from './settings.resolver'; | ||
import { PrismaService } from 'prisma/prisma.service'; | ||
|
||
@Module({ | ||
providers: [SettingsResolver, SettingsService, PrismaService], | ||
}) | ||
export class SettingsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { Args, Context, Mutation, Resolver } from '@nestjs/graphql'; | ||
import { PrismaService } from 'prisma/prisma.service'; | ||
import { UpdateLanguageInput } from 'src/graphql.types'; | ||
import { verifyJWT } from 'src/utils/jwt.utils'; | ||
import { SettingsService } from './settings.service'; | ||
|
||
@Resolver() | ||
export class SettingsResolver { | ||
constructor( | ||
private readonly settingsService: SettingsService, | ||
private readonly prismaService: PrismaService, | ||
) {} | ||
@Mutation('updateLanguage') | ||
async updateLanguage( | ||
@Args('input') input: UpdateLanguageInput, | ||
@Context() ctx, | ||
) { | ||
const { payload, expired } = verifyJWT( | ||
ctx.req.headers.authorization?.split(' ')[1], | ||
); | ||
if (expired) throw new BadRequestException('Token expired'); | ||
return await this.settingsService.updateLanguage(payload.id, input.lang); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from 'prisma/prisma.service'; | ||
|
||
@Injectable() | ||
export class SettingsService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
async updateLanguage(userId: string, language: string) { | ||
await this.prismaService.user.update({ | ||
where: { id: userId }, | ||
data: { language }, | ||
}); | ||
return 'Successfully updated language'; | ||
} | ||
} |