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