remove eom directives

This commit is contained in:
Moriz Wahl 2021-08-03 13:59:22 +02:00
parent 628f0a541f
commit 800e4e04fd
11 changed files with 13 additions and 274 deletions

View File

@ -1,184 +0,0 @@
import axios from 'axios'
import { graphql } from 'graphql'
import CONFIG from '../config'
import { User } from '../graphql/models/User'
import { LoginUserInput } from '../graphql/inputs/LoginUserInput'
// eslint-disable-next-line no-unused-vars
// import regeneratorRuntime from 'regenerator-runtime'
// control email-text sended with email verification code
const EMAIL_TYPE = {
DEFAULT: 2, // if user has registered directly
ADMIN: 5, // if user was registered by an admin
}
const apiGet = async (url: string) => {
try {
const result = await axios.get(url)
if (result.status !== 200) {
throw new Error('HTTP Status Error ' + result.status)
}
if (!['success', 'warning'].includes(result.data.state)) {
throw new Error(result.data.msg)
}
return { success: true, result }
} catch (error) {
return { success: false, result: error }
}
}
const apiPost = async (url: string, payload: any): Promise<any> => {
try {
const result = await axios.post(url, payload)
if (result.status !== 200) {
throw new Error('HTTP Status Error ' + result.status)
}
if (result.data.state === 'warning') {
return { success: true, result: result.data.errors }
}
if (result.data.state !== 'success') {
throw new Error(result.data.msg)
}
return { success: true, result }
} catch (error) {
return { success: false, result: error }
}
}
interface NetworkInfosResult {
state: string
msg?: string
errors: string[]
data: {
groups?: string[]
}
}
interface LoginResult {
state: string
msg?: string
details?: number
info?: string
user?: User
// eslint-disable-next-line camelcase
session_id?: number
}
const loginAPI = {
login: async (login: LoginUserInput): Promise<LoginResult> => {
return (await apiPost(CONFIG.LOGIN_API_URL + 'unsecureLogin', login)).result.data
},
logout: async (sessionId: number): Promise<any> => {
const payload: any = { session_id: sessionId }
return apiPost(CONFIG.LOGIN_API_URL + 'logout', payload)
},
create: async (
email: string,
firstName: string,
lastName: string,
password: string,
): Promise<any> => {
const payload: any = {
email,
first_name: firstName,
last_name: lastName,
password,
emailType: EMAIL_TYPE.DEFAULT,
login_after_register: true,
}
return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload)
},
sendEmail: async (
email: string,
email_text = 7,
email_verification_code_type = 'resetPassword',
): Promise<any> => {
const payload: any = {
email,
email_text,
email_verification_code_type,
}
return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload)
},
loginViaEmailVerificationCode: async (optin: number): Promise<any> => {
return apiGet(
CONFIG.LOGIN_API_URL + 'loginViaEmailVerificationCode?emailVerificationCode=' + optin,
)
},
getUserInfos: async (sessionId: number, email: string): Promise<any> => {
const payload: any = {
session_id: sessionId,
email: email,
ask: ['user.first_name', 'user.last_name'],
}
return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload)
},
updateUserInfos: async (sessionId: number, email: string, data: any): Promise<any> => {
const payload: any = {
session_id: sessionId,
email,
update: {
'User.first_name': data.firstName,
'User.last_name': data.lastName,
'User.description': data.description,
},
}
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
},
changePassword: async (sessionId: number, email: string, password: string): Promise<any> => {
const payload: any = {
session_id: sessionId,
email,
password,
}
return apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload)
},
changePasswordProfile: async (
sessionId: number,
email: string,
password: string,
passwordNew: string,
): Promise<any> => {
const payload: any = {
session_id: sessionId,
email,
update: {
'User.password_old': password,
'User.password': passwordNew,
},
}
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
},
changeUsernameProfile: async (
sessionId: number,
email: string,
username: string,
): Promise<any> => {
const payload: any = {
session_id: sessionId,
email,
update: {
'User.username': username,
},
}
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
},
updateLanguage: async (sessionId: number, email: string, language: string): Promise<any> => {
const payload: any = {
session_id: sessionId,
email,
update: {
'User.language': language,
},
}
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
},
checkUsername: async (username: string, groupId = 1): Promise<any> => {
return apiGet(CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`)
},
getNetworkInfos: async (ask: string[]): Promise<NetworkInfosResult> => {
return (await apiPost(CONFIG.LOGIN_API_URL + `networkInfos`, { ask: ask })).result.data
},
}
export { loginAPI, NetworkInfosResult, LoginResult }

View File

@ -1,27 +1,21 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity, Column } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType() @ObjectType()
export class Balance extends BaseEntity { export class Balance {
constructor(json: any) { constructor(json: any) {
super()
this.balance = Number(json.balance) this.balance = Number(json.balance)
this.decay = Number(json.decay) this.decay = Number(json.decay)
this.decayDate = json.decay_date this.decayDate = json.decay_date
} }
@Field(() => Number) @Field(() => Number)
@Column()
balance: number balance: number
@Field(() => Number) @Field(() => Number)
@Column()
decay: number decay: number
@Field(() => String) @Field(() => String)
@Column()
decayDate: string decayDate: string
} }

View File

@ -1,13 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType() @ObjectType()
export class CheckUsernameResponse extends BaseEntity { export class CheckUsernameResponse {
constructor(json: any) { constructor(json: any) {
super()
this.state = json.state this.state = json.state
this.msg = json.msg this.msg = json.msg
this.groupId = json.group_id this.groupId = json.group_id

View File

@ -1,16 +0,0 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity } from 'typeorm'
import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType()
export class CreateResponse extends BaseEntity {
constructor(json: any) {
super()
this.state = json.state
}
@Field(() => String)
state: string
}

View File

@ -1,25 +1,20 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity, Column } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
import { User } from './User' import { User } from './User'
// temporaray solution until we have JWT implemented // temporaray solution until we have JWT implemented
@Entity()
@ObjectType() @ObjectType()
export class LoginResponse extends BaseEntity { export class LoginResponse {
constructor(json: any) { constructor(json: any) {
super()
this.sessionId = json.session_id this.sessionId = json.session_id
this.user = new User(json.user) this.user = new User(json.user)
} }
@Field(() => Number) @Field(() => Number)
@Column()
sessionId: number sessionId: number
@Field(() => User) @Field(() => User)
@Column()
user: User user: User
} }

View File

@ -1,22 +1,17 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity, Column } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType() @ObjectType()
export class LoginViaVerificationCode extends BaseEntity { export class LoginViaVerificationCode {
constructor(json: any) { constructor(json: any) {
super()
this.sessionId = json.session_id this.sessionId = json.session_id
this.email = json.user.email this.email = json.user.email
} }
@Field(() => Number) @Field(() => Number)
@Column()
sessionId: number sessionId: number
@Field(() => String) @Field(() => String)
@Column()
email: string email: string
} }

View File

@ -1,16 +0,0 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity } from 'typeorm'
import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType()
export class ResetPasswordResponse extends BaseEntity {
constructor(json: any) {
super()
this.state = json.state
}
@Field(() => String)
state: string
}

View File

@ -1,13 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType() @ObjectType()
export class SendPasswordResetEmailResponse extends BaseEntity { export class SendPasswordResetEmailResponse {
constructor(json: any) { constructor(json: any) {
super()
this.state = json.state this.state = json.state
this.msg = json.msg this.msg = json.msg
} }

View File

@ -1,13 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType() @ObjectType()
export class UpdateUserInfosResponse extends BaseEntity { export class UpdateUserInfosResponse {
constructor(json: any) { constructor(json: any) {
super()
this.validValues = json.valid_values this.validValues = json.valid_values
} }

View File

@ -1,18 +1,15 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Entity, BaseEntity, Column } from 'typeorm'
import { ObjectType, Field } from 'type-graphql' import { ObjectType, Field } from 'type-graphql'
@Entity()
@ObjectType() @ObjectType()
export class User extends BaseEntity { export class User {
/* /*
@Field(() => ID) @Field(() => ID)
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
id: number id: number
*/ */
constructor(json: any) { constructor(json: any) {
super()
this.email = json.email this.email = json.email
this.firstName = json.first_name this.firstName = json.first_name
this.lastName = json.last_name this.lastName = json.last_name
@ -22,62 +19,49 @@ export class User extends BaseEntity {
} }
@Field(() => String) @Field(() => String)
@Column({ length: 191 })
email: string email: string
@Field(() => String) @Field(() => String)
@Column({ length: 150 })
firstName: string firstName: string
@Field(() => String) @Field(() => String)
@Column()
lastName: string lastName: string
@Field(() => String) @Field(() => String)
@Column()
username: string username: string
@Field(() => String) @Field(() => String)
@Column('text')
description: string description: string
/* /*
@Field(() => String) @Field(() => String)
@Column({ length: 64 })
pubkey: string pubkey: string
// not sure about the type here. Maybe better to have a string // not sure about the type here. Maybe better to have a string
@Field(() => number) @Field(() => number)
@Column({ type: 'datetime' })
created: number created: number
@Field(() => Boolean) @Field(() => Boolean)
@Column({ default: false })
emailChecked: boolean emailChecked: boolean
@Field(() => Boolean) @Field(() => Boolean)
@Column({ default: false })
passphraseShown: boolean passphraseShown: boolean
*/ */
@Field(() => String) @Field(() => String)
@Column({ default: 'de' })
language: string language: string
/* /*
@Field(() => Boolean) @Field(() => Boolean)
@Column({ default: false })
disabled: boolean disabled: boolean
*/ */
/* I suggest to have a group as type here /* I suggest to have a group as type here
@Field(() => ID) @Field(() => ID)
@Column()
groupId: number groupId: number
// what is puvlisherId? // what is puvlisherId?
@Field(() => ID) @Field(() => ID)
@Column({ default: 0 })
publisherId: number publisherId: number
*/ */
} }

View File

@ -1,9 +1,7 @@
// import jwt from 'jsonwebtoken' // import jwt from 'jsonwebtoken'
import { Resolver, Query, Args, Arg } from 'type-graphql' import { Resolver, Query, Args, Arg } from 'type-graphql'
import CONFIG from '../../config' import CONFIG from '../../config'
import { ResetPasswordResponse } from '../models/ResetPasswordResponse'
import { CheckUsernameResponse } from '../models/CheckUsernameResponse' import { CheckUsernameResponse } from '../models/CheckUsernameResponse'
import { CreateResponse } from '../models/CreateResponse'
import { GetUserInfoResponse } from '../models/UserInfoData' import { GetUserInfoResponse } from '../models/UserInfoData'
import { LoginResponse } from '../models/LoginResponse' import { LoginResponse } from '../models/LoginResponse'
import { LoginViaVerificationCode } from '../models/LoginViaVerificationCode' import { LoginViaVerificationCode } from '../models/LoginViaVerificationCode'
@ -74,10 +72,8 @@ export class UserResolver {
return 'success' return 'success'
} }
@Query(() => CreateResponse) @Query(() => String)
async create( async create(@Args() { email, firstName, lastName, password }: CreateUserArgs): Promise<string> {
@Args() { email, firstName, lastName, password }: CreateUserArgs,
): Promise<CreateResponse> {
const payload = { const payload = {
email, email,
first_name: firstName, first_name: firstName,
@ -90,7 +86,7 @@ export class UserResolver {
if (!result.success) { if (!result.success) {
throw new Error(result.data) throw new Error(result.data)
} }
return new CreateResponse(result.data) return 'success'
} }
// TODO // TODO
@ -120,11 +116,11 @@ export class UserResolver {
return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload) return apiPost(CONFIG.LOGIN_API_URL + 'getUserInfos', payload)
} }
@Query(() => ResetPasswordResponse) @Query(() => String)
async resetPassword( async resetPassword(
@Args() @Args()
{ sessionId, email, password }: ChangePasswordArgs, { sessionId, email, password }: ChangePasswordArgs,
): Promise<ResetPasswordResponse> { ): Promise<string> {
const payload = { const payload = {
session_id: sessionId, session_id: sessionId,
email, email,
@ -132,7 +128,7 @@ export class UserResolver {
} }
const result = await apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload) const result = await apiPost(CONFIG.LOGIN_API_URL + 'resetPassword', payload)
if (!result.success) throw new Error(result.data) if (!result.success) throw new Error(result.data)
return new ResetPasswordResponse(result.data) return 'sucess'
} }
@Query(() => UpdateUserInfosResponse) @Query(() => UpdateUserInfosResponse)