mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add User Model and Resolver
This commit is contained in:
parent
34b30b216b
commit
9cd14d1304
2
backend/.env.dist
Normal file
2
backend/.env.dist
Normal file
@ -0,0 +1,2 @@
|
||||
LOGIN_API_URL=http://localhost/login_api/
|
||||
COMMUNITY_API_URL=http://localhost/api/
|
||||
@ -12,6 +12,7 @@
|
||||
"lint": "eslint . --ext .js,.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-datasource-rest": "^0.14.0",
|
||||
"express": "^4.17.1",
|
||||
"express-graphql": "^0.12.0",
|
||||
"graphql": "^15.5.1",
|
||||
|
||||
24
backend/src/config/index.ts
Normal file
24
backend/src/config/index.ts
Normal file
@ -0,0 +1,24 @@
|
||||
// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env)
|
||||
|
||||
// Load Package Details for some default values
|
||||
const pkg = require('../../package')
|
||||
|
||||
const environment = {
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
DEBUG: process.env.NODE_ENV !== 'production' || false,
|
||||
PRODUCTION: process.env.NODE_ENV === 'production' || false,
|
||||
ALLOW_REGISTER: process.env.ALLOW_REGISTER !== 'false',
|
||||
}
|
||||
|
||||
const server = {
|
||||
LOGIN_API_URL: process.env.LOGIN_API_URL || 'http://localhost/login_api/',
|
||||
COMMUNITY_API_URL: process.env.COMMUNITY_API_URL || 'http://localhost/api/',
|
||||
}
|
||||
|
||||
const CONFIG = {
|
||||
...environment,
|
||||
...server,
|
||||
APP_VERSION: pkg.version,
|
||||
}
|
||||
|
||||
export default CONFIG
|
||||
8
backend/src/graphql/datasources/login_server.ts
Normal file
8
backend/src/graphql/datasources/login_server.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { RESTDataSource } from 'apollo-datasource-rest'
|
||||
|
||||
export class LoginServerAPI extends RESTDataSource {
|
||||
constructor() {
|
||||
super()
|
||||
this.baseURL = 'https://api.spacexdata.com/v2/'
|
||||
}
|
||||
}
|
||||
62
backend/src/graphql/models/User.ts
Normal file
62
backend/src/graphql/models/User.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { Entity, BaseEntity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { ObjectType, Field, ID, GraphQLISODateTime } from 'type-graphql'
|
||||
|
||||
@Entity()
|
||||
@ObjectType()
|
||||
export class User extends BaseEntity {
|
||||
@Field(() => ID)
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ length: 191 })
|
||||
email: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ length: 150 })
|
||||
firstName: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
lastName: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
username: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column('text')
|
||||
description: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ length: 64 })
|
||||
pubkey: string
|
||||
|
||||
@Field(() => GraphQLISODateTime)
|
||||
@Column({ type: 'datetime' })
|
||||
created: Date
|
||||
|
||||
@Field(() => Boolean)
|
||||
@Column({ default: false })
|
||||
emailChecked: boolean
|
||||
|
||||
@Field(() => Boolean)
|
||||
@Column({ default: false })
|
||||
passphraseShown: boolean
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ default: 'de' })
|
||||
language: string
|
||||
|
||||
@Field(() => Boolean)
|
||||
@Column({ default: false })
|
||||
disabled: boolean
|
||||
|
||||
@Field(() => ID)
|
||||
@Column()
|
||||
groupId: number
|
||||
|
||||
@Field(() => ID)
|
||||
@Column({ default: 0 })
|
||||
publisherId: number
|
||||
}
|
||||
42
backend/src/graphql/resolvers/UserResolver.ts
Normal file
42
backend/src/graphql/resolvers/UserResolver.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { Resolver, Query, Mutation, Arg } from 'type-graphql'
|
||||
import { User } from '../models/User'
|
||||
// import { CreateBookInput } from '../inputs/CreateBookInput'
|
||||
// import { UpdateBookInput } from '../inputs/UpdateBookInput'
|
||||
|
||||
@Resolver()
|
||||
export class UserResolver {
|
||||
@Query(() => [User])
|
||||
users(): Promise<User[]> {
|
||||
return User.find()
|
||||
}
|
||||
|
||||
@Query(() => User)
|
||||
user(@Arg('id') id: string): Promise<User | undefined> {
|
||||
return User.findOne({ where: { id } })
|
||||
}
|
||||
|
||||
/*
|
||||
@Mutation(() => User)
|
||||
async createBook(@Arg('data') data: CreateBookInput) {
|
||||
const book = User.create(data)
|
||||
await book.save()
|
||||
return book
|
||||
}
|
||||
|
||||
@Mutation(() => Book)
|
||||
async updateBook(@Arg('id') id: string, @Arg('data') data: UpdateBookInput) {
|
||||
const book = await Book.findOne({ where: { id } })
|
||||
if (!book) throw new Error('Book not found!')
|
||||
Object.assign(book, data)
|
||||
await book.save()
|
||||
return book
|
||||
}
|
||||
*/
|
||||
@Mutation(() => Boolean)
|
||||
async deleteUser(@Arg('id') id: string): Promise<boolean> {
|
||||
const user = await User.findOne({ where: { id } })
|
||||
if (!user) throw new Error('User not found!')
|
||||
await user.remove()
|
||||
return true
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user