mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
bring load and save coinanimation to live
This commit is contained in:
parent
a5d6b510f5
commit
b5a7af16e7
2
backend/.gitignore
vendored
2
backend/.gitignore
vendored
@ -1,7 +1,7 @@
|
||||
/node_modules/
|
||||
/.env
|
||||
/build/
|
||||
|
||||
package-json.lock
|
||||
coverage
|
||||
# emacs
|
||||
*~
|
||||
@ -69,6 +69,9 @@ export class User {
|
||||
@Field(() => Number)
|
||||
publisherId: number
|
||||
|
||||
@Field(() => Boolean)
|
||||
coinanimation: boolean
|
||||
|
||||
@Field(() => KlickTipp)
|
||||
klickTipp: KlickTipp
|
||||
}
|
||||
|
||||
@ -43,8 +43,15 @@ export class UserResolver {
|
||||
key: 'token',
|
||||
value: encode(result.data.session_id, result.data.user.public_hex),
|
||||
})
|
||||
|
||||
return new User(result.data.user)
|
||||
const user = new User(result.data.user)
|
||||
// read additional settings from settings table
|
||||
const userSettingRepository = getCustomRepository(UserSettingRepository)
|
||||
const userEntity = await dbUser.findByPubkeyHex(user.pubkey)
|
||||
const coinanimation = await userSettingRepository.readBoolean(userEntity.id, Setting.COIN_ANIMATION).catch((error) => {
|
||||
throw new Error(error)
|
||||
})
|
||||
user.coinanimation = coinanimation
|
||||
return user
|
||||
}
|
||||
|
||||
@Query(() => LoginViaVerificationCode)
|
||||
@ -133,7 +140,6 @@ export class UserResolver {
|
||||
async updateUserInfos(
|
||||
@Args()
|
||||
{
|
||||
email,
|
||||
firstName,
|
||||
lastName,
|
||||
description,
|
||||
@ -148,7 +154,6 @@ export class UserResolver {
|
||||
): Promise<UpdateUserInfosResponse> {
|
||||
const payload = {
|
||||
session_id: context.sessionId,
|
||||
email,
|
||||
update: {
|
||||
'User.first_name': firstName || undefined,
|
||||
'User.last_name': lastName || undefined,
|
||||
@ -190,7 +195,9 @@ export class UserResolver {
|
||||
userEntity.id,
|
||||
Setting.COIN_ANIMATION,
|
||||
coinanimation.toString(),
|
||||
)
|
||||
).catch((error) => {
|
||||
throw new Error(error)
|
||||
})
|
||||
|
||||
if (!response) {
|
||||
response = new UpdateUserInfosResponse({ valid_values: 1 })
|
||||
|
||||
@ -2,7 +2,7 @@ import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 't
|
||||
import { User } from './User'
|
||||
|
||||
@Entity()
|
||||
export class UserSetting extends BaseEntity {
|
||||
export class UserSetting { //extends BaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
|
||||
@ -3,8 +3,9 @@ import { UserSetting } from '../entity/UserSetting'
|
||||
import { Setting } from '../../types'
|
||||
import { isStringBoolean } from '../../util/validate'
|
||||
|
||||
@EntityRepository()
|
||||
@EntityRepository(UserSetting)
|
||||
export class UserSettingRepository extends Repository<UserSetting> {
|
||||
|
||||
async setOrUpdate(userId: number, key: Setting, value: string): Promise<UserSetting> {
|
||||
switch (key) {
|
||||
case Setting.COIN_ANIMATION:
|
||||
@ -23,4 +24,12 @@ export class UserSettingRepository extends Repository<UserSetting> {
|
||||
entity.value = value
|
||||
return this.save(entity)
|
||||
}
|
||||
|
||||
async readBoolean(userId: number, key: Setting): Promise<boolean> {
|
||||
let entity = await this.findOne({ userId: userId, key: key })
|
||||
if(!entity || !isStringBoolean(entity.value)) {
|
||||
return false
|
||||
}
|
||||
return entity.value.toLowerCase() === 'true'
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
|
||||
await queryFn(`
|
||||
CREATE TABLE IF NOT EXISTS \`userSetting\` (
|
||||
CREATE TABLE IF NOT EXISTS \`user_setting\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`userId\` int(11) NOT NULL,
|
||||
\`key\` varchar(255) NOT NULL,
|
||||
@ -23,6 +23,6 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write downgrade logic as parameter of queryFn
|
||||
await queryFn(`DROP TABLE IF EXISTS \`userSettings\`;`)
|
||||
await queryFn(`DROP TABLE IF EXISTS \`user_setting\`;`)
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ export const resetPassword = gql`
|
||||
|
||||
export const updateUserInfos = gql`
|
||||
mutation(
|
||||
$email: String!
|
||||
$firstName: String
|
||||
$lastName: String
|
||||
$description: String
|
||||
@ -28,9 +27,9 @@ export const updateUserInfos = gql`
|
||||
$password: String
|
||||
$passwordNew: String
|
||||
$locale: String
|
||||
$coinanimation: Boolean
|
||||
) {
|
||||
updateUserInfos(
|
||||
email: $email
|
||||
firstName: $firstName
|
||||
lastName: $lastName
|
||||
description: $description
|
||||
@ -38,6 +37,7 @@ export const updateUserInfos = gql`
|
||||
password: $password
|
||||
passwordNew: $passwordNew
|
||||
language: $locale
|
||||
coinanimation: $coinanimation
|
||||
) {
|
||||
validValues
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ export const login = gql`
|
||||
lastName
|
||||
language
|
||||
description
|
||||
coinanimation
|
||||
klickTipp {
|
||||
newsletterState
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
v-model="CoinAnimationStatus"
|
||||
name="check-button"
|
||||
switch
|
||||
@change="onSubmit"
|
||||
>
|
||||
{{
|
||||
CoinAnimationStatus
|
||||
@ -30,7 +31,7 @@
|
||||
</b-card>
|
||||
</template>
|
||||
<script>
|
||||
import { updateUserInfos } from '../../../graphql/queries'
|
||||
import { updateUserInfos } from '../../../graphql/mutations'
|
||||
export default {
|
||||
name: 'FormUserCoinAnimation',
|
||||
data() {
|
||||
@ -39,13 +40,13 @@ export default {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.CoinAnimationStatus = this.$store.state.coinanimation /* exestiert noch nicht im store */
|
||||
this.CoinAnimationStatus = this.$store.state.coinanimation /* existiert noch nicht im store */
|
||||
},
|
||||
methods: {
|
||||
async onSubmit() {
|
||||
this.$apollo
|
||||
.query({
|
||||
query: updateUserInfos,
|
||||
.mutate({
|
||||
mutation: updateUserInfos,
|
||||
variables: {
|
||||
coinanimation: this.$store.state.coinanimation,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user