Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as dotenv from 'dotenv'
import * as path from 'path';

console.log(`process.env.NODE_ENV ---> : ${process.env.NODE_ENV}`)
dotenv.config({ path: path.resolve(__dirname, `./config/${process.env.NODE_ENV||''}.env`) });

const envVars = [
Expand All @@ -23,7 +24,12 @@ const envVars = [
'STRIPE_WEBHOOK_SECRET',
'PINATA_API_KEY',
'PINATA_SECRET_API_KEY',
'UPLOAD_MAX_FILE_SIZE'
'UPLOAD_MAX_FILE_SIZE',
'DB_DROP_SEED',
'SEED_PASSWORD',
'SERVER_ADMIN',
'DEFAULT_ORGANISATION',
'UPLOAD_FILE_MAX_SIZE'
]

class Config {
Expand Down Expand Up @@ -63,6 +69,9 @@ class Config {
}

get (envVar: string): string | number {
if(!this[envVar]) {
throw new Error(`${envVar} is an invalid env variable`)
}
return this[envVar]
}
}
Expand Down
2 changes: 1 addition & 1 deletion entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Project extends BaseEntity {

@Field({ nullable: true })
@Column({ nullable: true })
admin?: string
admin?: number

@Field({ nullable: true })
@Column({ nullable: true })
Expand Down
173 changes: 119 additions & 54 deletions helpers.ts

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ export class ProjectResolver {

@Query(returns => [Project])
async projects (@Args() { take, skip, admin }: GetProjectsArgs): Promise<Project[]> {

return !admin? this.projectRepository.find({ take, skip }) : this.projectRepository.find({
where: { admin },
take, skip
})

}

@Query(returns => TopProjects)
Expand Down Expand Up @@ -191,8 +193,9 @@ export class ProjectResolver {
if (!user) throw new Error('Authentication required.')

const project = await Project.findOne({ id: projectId });

if (!project) throw new Error('Project not found.');

if (project.admin != user.userId) throw new Error('You are not the owner of this project.')

for (const field in newProjectData)
Expand Down
8 changes: 7 additions & 1 deletion resolvers/types/project-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export class ProjectInput {
title: string

@Field({ nullable: true })
admin?: string
slug?: string;

@Field({ nullable: true })
admin?: number

@Field({ nullable: true })
@Length(0, 255)
Expand All @@ -26,6 +29,9 @@ export class ProjectInput {
@Field({ nullable: true })
imageStatic?: string

@Field({ nullable: true })
image?: string;

@Field({ nullable: true })
impactLocation?: string

Expand Down
18 changes: 17 additions & 1 deletion server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,23 @@ export async function bootstrap() {
app.use(cors())
apolloServer.applyMiddleware({ app });
app.post('/stripe-webhook', bodyParser.raw({ type: 'application/json' }), handleStripeWebhook);

app.get('/project', (req, res) => {
res.send({
balance: 0,
id: 24,
title: 'James test project',
slug: 'James-test-project',
admin: '17',
description: 'This is a super cool description!!!!',
organisationId: 1212121212,
coOrdinates: '0.342434, 0.3434343',
image: 'https://ipfs.giveth.io/ipfs/QmYx4eCHQFLJNEKWLjFQGR8hisEtdDbYqGKHSmCWuRvufa',
impactLocation: null,
stripeAccountId: null,
walletAddress: '0xD2CAc44B9d072A0D6bD39482147d894f13C5CF32',
categories: ['carbon', 'biodiversity']
})
})
// Start the server
app.listen({ port: 4000 })
console.log(`🚀 Server is running, GraphQL Playground available at http://127.0.0.1:${4000}/graphql`)
Expand Down
16 changes: 8 additions & 8 deletions server/createSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const createSchema = async (): Promise<GraphQLSchema> => {
database: config.get('TYPEORM_DATABASE_NAME') as string,
username: config.get('TYPEORM_DATABASE_USER') as string,
password: config.get('TYPEORM_DATABASE_PASSWORD') as string,
port: config.get('PORT') as number,
port: config.get('TYPEORM_DATABASE_PORT') as number,
host: config.get('TYPEORM_DATABASE_HOST') as string,
entities,
synchronize: true,
Expand All @@ -32,12 +32,12 @@ const createSchema = async (): Promise<GraphQLSchema> => {
dropSchema,
cache: true
})

// if (dropSchema) {
// // seed database with some data
// const { defaultUser } = await seedDatabase()
// }
//
const dropSeed = config.get('DB_DROP_SEED') ? config.get('DB_DROP_SEED') : false
if (dropSeed) {
// seed database with some data
// Removed for go live, in future this can be used to init the db with data, such as seed projects or categories
const { defaultUser } = await seedDatabase()
}

// build TypeGraphQL executable schema
const schema = await TypeGraphQL.buildSchema({
Expand All @@ -48,4 +48,4 @@ const createSchema = async (): Promise<GraphQLSchema> => {
return schema
}

export default createSchema;
export default createSchema;
4 changes: 1 addition & 3 deletions user/LoginResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ export class LoginResolver {
avatar
}).save()

console.log(`user saved : ${JSON.stringify(user, null, 2)}`)
} else {
console.log('user exists already')


user.avatar = avatar;
if(name) user.name = name;
await user.save();
Expand Down