diff --git a/config.ts b/config.ts index 1f20baea6..225495be8 100644 --- a/config.ts +++ b/config.ts @@ -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 = [ @@ -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 { @@ -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] } } diff --git a/entities/project.ts b/entities/project.ts index 2231fdb77..2c0af210a 100644 --- a/entities/project.ts +++ b/entities/project.ts @@ -51,7 +51,7 @@ class Project extends BaseEntity { @Field({ nullable: true }) @Column({ nullable: true }) - admin?: string + admin?: number @Field({ nullable: true }) @Column({ nullable: true }) diff --git a/helpers.ts b/helpers.ts index c5603ac76..516ae2ff4 100644 --- a/helpers.ts +++ b/helpers.ts @@ -1,3 +1,4 @@ +import config from './config'; import { getRepository, Column, ColumnOptions } from 'typeorm' import * as bcrypt from 'bcryptjs' @@ -14,73 +15,137 @@ export async function seedDatabase () { // const organisationProjectRepository = getRepository(OrganisationProject) const userRepository = getRepository(User) - const seedPassword = 'qweqweqwe' + console.log(`config.get('SEED_PASSWORD') ---> : ${config.get('SEED_PASSWORD')}`) + const seedPassword = config.get('SEED_PASSWORD').toString() + const serverEmail = config.get('SERVER_ADMIN').toString() + let users: User[] = [] const superAdminUser = userRepository.create({ - email: 'jamespfarrell@gmail.com', - firstName: 'James', - password: bcrypt.hashSync(seedPassword, 12), - confirmed: true, - loginType: 'password' - }) - const icrcAdmin = userRepository.create({ - email: 'icrcAdmin@icrcAdmin.com', - firstName: 'icrcAdmin', + email: serverEmail, + firstName: 'admin', password: bcrypt.hashSync(seedPassword, 12), confirmed: true, loginType: 'password' }) - const ifrcAdmin = userRepository.create({ - email: 'ifrcAdmin@icrcAdmin.com', - firstName: 'ifrcAdmin', - password: bcrypt.hashSync(seedPassword, 12), - confirmed: true, - loginType: 'password' - }) - await userRepository.save([superAdminUser, icrcAdmin, ifrcAdmin]) - - const covidProject = projectRepository.create({ - title: 'COVID-19: ICRC global response to the coronavirus', - description: `Professionals with a background in health, disaster management, water, sanitation, food and economic security, and logistics attended the 4th edition of the Regional HELP (Health Emergencies in Large Populations) course held in Delhi from 24 February to 6 March 2020. The two-week programme prepared participants, who came from nine countries, for effectively leading an emergency health response. - - In India, the HELP course is organized by the ICRC in partnership with International Institute of Health Management Research (IIHMR), National Institute of Disaster Management, World Health Organization (WHO) and the Indian Red Cross Society. It aims to enhance professionalism in health emergency response with an emphasis on decision-making. It uses the public health approach, fostering multidisciplinary responses and bringing out challenges, dilemmas, norms, standards and principles. This synergy between the field expertise of the ICRC and the academic expertise of IIHMR makes the course different from other HELP courses conducted around the world.` - }) - console.log(`aProject1 : ${JSON.stringify(covidProject, null, 2)}`) - - await projectRepository.save(covidProject) - console.log(`aProject2 : ${JSON.stringify(covidProject, null, 2)}`) - - const icrcOrg = organisationRepository.create([ - { - title: 'International Committee of the Red Cross (ICRC)', - description: - 'Established in 1863, the ICRC operates worldwide, helping people affected by conflict and armed violence and promoting the laws that protect victims of war. An independent and neutral organization, its mandate stems essentially from the Geneva Conventions of 1949. We are based in Geneva, Switzerland, and employ some 16,000 people in more than 80 countries. The ICRC is funded mainly by voluntary donations from governments and from National Red Cross and Red Crescent Societies.' - }, - { + users.push(superAdminUser) + + let projects: Project[] = [] + let organisations: Organisation[] = [] + + if(config.get('DEFAULT_ORGANISATION') === 'giveth' ) { + const givethAdmin = userRepository.create({ + email: 'james@giveth.io', + firstName: 'admin', + password: bcrypt.hashSync(seedPassword, 12), + confirmed: true, + loginType: 'password' + }) + users.push(givethAdmin) + await userRepository.save(users) + const project1 = projectRepository.create({ title: 'Giveth', - description: 'Giveth is the future of giving.' - }, - { - title: 'Gaia Protection', - description: - 'The Madre Tierra Verde Foundation aims to contribute to the transition of Costa Rican society towards a paradigm of a green and intelligent society, following the guidelines of the National Strategy for Decarbonizing the Economy, through guidance and advice to organizations, communities and governments.' - } - ]) - - await organisationRepository.save(icrcOrg) + description: `The future of Giving + Unlike traditional charity, with Giveth every donation and pledge is transparent, so you always know exactly where your donation went and get a good sense of the impact it made in direct communication with your beneficiary.`, + organisationId: 1, + admin: 2, + walletAddress: 'revolution.eth', + slug: 'giveth', + image: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgoKPHN2ZwogICB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iCiAgIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiCiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIKICAgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxuczpzb2RpcG9kaT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBvZGktMC5kdGQiCiAgIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIgogICB3aWR0aD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AgICAgICAgICAgaWQ9InBhdGg0NCIKICAgICAgICAgICAgIGlua3NjYXBlOmNvbm5lY3Rvci1jdXJ2YXR1cmU9IjAiIC8+CiAgICAgICAgPC9nPgogICAgICA8L2c+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K' + }) + projects.push(project1) + organisations = organisationRepository.create([ + { + title: 'Giveth', + description: 'Giveth is the future of giving.' + }, + { + title: 'Gaia Protection', + description: + 'The Madre Tierra Verde Foundation aims to contribute to the transition of Costa Rican society towards a paradigm of a green and intelligent society, following the guidelines of the National Strategy for Decarbonizing the Economy, through guidance and advice to organizations, communities and governments.' + } + ]) + await organisationRepository.save(organisations) + const adminOrganisationUser = organisationUserRepository.create({ + role: 'admin', + organisation: organisations[0], + user: givethAdmin + }) + console.log(`adminOrganisationUser : ${JSON.stringify(adminOrganisationUser, null, 2)}`) + + await organisationUserRepository.save(adminOrganisationUser) + } else { + // Organisation 1 + const co2kenAdmin = userRepository.create({ + email: 'admin@co2ken.io', + firstName: 'CO2ken', + password: bcrypt.hashSync(seedPassword, 12), + confirmed: true, + loginType: 'password' + }) + users.push(co2kenAdmin) + await userRepository.save(users) + const project1 = projectRepository.create({ + title: 'Ecoera', + description: `Become Climate Positive + We enable the Carbon Transformation by making your organisation go climate positive using carbon removal from our sustainable biochar carbon sink.`, + organisationId: 2, + admin: 2, + walletAddress: '0x63A32F1595a68E811496D820680B74A5ccA303c5', + slug: 'ecoera', + image: 'https://cdn.shopify.com/s/files/1/2556/2892/files/BiokolBigbag_3000x.JPG?v=1511514366' + }) + const project2 = projectRepository.create({ + title: 'REDD+ Papua New Guinea', + description: `Why only Offsett and Reduce your carbon footprint? Our Validated, Verified, and Registered Carbon Credits conserve endangered tropical rainforests in Papua New Guinea and generate historical economic growth and social transformation for its people.`, + organisationId: 2, + admin: 2, + walletAddress: '0x63A32F1595a68E811496D820680B74A5ccA303c5', + slug: 'redd-papua-new-guinea', + image: 'https://offsetra.com/agrocortex_banner.jpg' + }) + projects.push(project1) + projects.push(project2) + + organisations = organisationRepository.create([ + { + title: 'CO2ken', + description: + 'We tokenize carbon offsets to make them available for Ethereums web3 ecosystem.' + }, + { + title: 'Giveth', + description: 'Giveth is the future of giving.' + }, + { + title: 'Gaia Protection', + description: + 'The Madre Tierra Verde Foundation aims to contribute to the transition of Costa Rican society towards a paradigm of a green and intelligent society, following the guidelines of the National Strategy for Decarbonizing the Economy, through guidance and advice to organizations, communities and governments.' + } + ]) + await organisationRepository.save(organisations) + const adminOrganisationUser = organisationUserRepository.create({ + role: 'admin', + organisation: organisations[0], + user: co2kenAdmin + }) + await organisationUserRepository.save(adminOrganisationUser) + } + + + + await projectRepository.save(projects) + + + + // Seed join table // const organisationProject = organisationProjectRepository.create({ - // organisation: icrcOrg[0], + // organisation: testOrganizations[0], // project: covidProject // }) // await organisationProjectRepository.save(organisationProject) - const adminOrganisationUser = organisationUserRepository.create({ - role: 'admin', - organisation: icrcOrg[0], - user: icrcAdmin - }) - await organisationUserRepository.save(adminOrganisationUser) + // const icrcProjects = projectRepository.create([ // { diff --git a/resolvers/projectResolver.ts b/resolvers/projectResolver.ts index aa21be532..8808ca7bd 100644 --- a/resolvers/projectResolver.ts +++ b/resolvers/projectResolver.ts @@ -141,10 +141,12 @@ export class ProjectResolver { @Query(returns => [Project]) async projects (@Args() { take, skip, admin }: GetProjectsArgs): Promise { + return !admin? this.projectRepository.find({ take, skip }) : this.projectRepository.find({ where: { admin }, take, skip }) + } @Query(returns => TopProjects) @@ -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) diff --git a/resolvers/types/project-input.ts b/resolvers/types/project-input.ts index dee71e4da..d9fec3abc 100644 --- a/resolvers/types/project-input.ts +++ b/resolvers/types/project-input.ts @@ -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) @@ -26,6 +29,9 @@ export class ProjectInput { @Field({ nullable: true }) imageStatic?: string + @Field({ nullable: true }) + image?: string; + @Field({ nullable: true }) impactLocation?: string diff --git a/server/bootstrap.ts b/server/bootstrap.ts index 0cdb14591..e73d2c646 100644 --- a/server/bootstrap.ts +++ b/server/bootstrap.ts @@ -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`) diff --git a/server/createSchema.ts b/server/createSchema.ts index 3d0e6e4cf..d0cf022a6 100644 --- a/server/createSchema.ts +++ b/server/createSchema.ts @@ -23,7 +23,7 @@ const createSchema = async (): Promise => { 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, @@ -32,12 +32,12 @@ const createSchema = async (): Promise => { 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({ @@ -48,4 +48,4 @@ const createSchema = async (): Promise => { return schema } -export default createSchema; \ No newline at end of file +export default createSchema; diff --git a/user/LoginResolver.ts b/user/LoginResolver.ts index e4ce60815..a11e092d4 100644 --- a/user/LoginResolver.ts +++ b/user/LoginResolver.ts @@ -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();