Skip to content

Commit

Permalink
Merge pull request #350 from setlife-network/release/1.1-rc1
Browse files Browse the repository at this point in the history
Release/1.1 rc1
  • Loading branch information
otech47 committed Mar 5, 2021
2 parents 8ad9977 + 4b9e06c commit 4688271
Show file tree
Hide file tree
Showing 31 changed files with 985 additions and 106 deletions.
2 changes: 1 addition & 1 deletion api/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const associations = ({ Allocation, Client, Contributor, Issue, Payment, Permiss
Contributor.hasMany(Permission, { foreignKey: 'contributor_id' })
Payment.hasMany(Allocation, { foreignKey: 'payment_id' })
Project.hasMany(Allocation, { foreignKey: 'project_id' })
Project.belongsTo(Client, { foreignKey: 'client_id' })
Client.hasMany(Project, { foreignKey: 'client_id' })
Project.hasMany(Permission, { foreignKey: 'project_id' })
Issue.belongsTo(Project, { foreignKey: 'project_id' })
Rate.hasMany(Allocation, { foreignKey: 'rate_id' })
Expand Down
2 changes: 0 additions & 2 deletions api/modules/dataSyncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ const dataSyncs = module.exports = (() => {

const syncInvoicelyCSV = async () => {
const invoiceFile = INVOICELY_CSV_PATH
console.log('invoiceFile')
console.log(invoiceFile)
return (
amazon.fetchFile({ file: invoiceFile })
.then(file => {
Expand Down
33 changes: 32 additions & 1 deletion api/schema/resolvers/ContributorResolver.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
const { AuthenticationError } = require('apollo-server')
const { col, fn } = require('sequelize')

const toggl = require('../../handlers/toggl')

module.exports = {
Contributor: {
paidByCurrency: async (contributor, args, { models }) => {
const totalPaidByCurrencyQuery = await models.Client.findAll({
group: 'currency',
attributes: ['currency'],
raw: true,
include: {
model: models.Project,
attributes: [],
required: true,
include: {
model: models.Allocation,
attributes: [[fn('sum', col('amount')), 'amount']],
where: {
contributor_id: contributor.id
},
}
}
})
totalPaidByCurrency = []
totalPaidByCurrencyQuery.map(t => {
totalPaidByCurrency.push(
{
currency: t['currency'],
amount: t['Projects.Allocations.amount']
}
)
})
return totalPaidByCurrency
},
permissions: (contributor, args, { models }) => {
return models.Permission.findAll({
where: {
Expand All @@ -17,7 +48,7 @@ module.exports = {
}
})
},
total_paid: async (contributor, args, { models }) => {
totalPaid: async (contributor, args, { models }) => {
const totalPaid = await models.Allocation.sum('amount', {
where: {
contributor_id: contributor.id
Expand Down
8 changes: 4 additions & 4 deletions api/schema/resolvers/ProjectResolver.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const moment = require('moment')
const sequelize = require('sequelize');
const sequelize = require('sequelize')
const { ApolloError } = require('apollo-server')
const { col, fn, Op } = require('sequelize');
const { col, fn, Op } = require('sequelize')
const { split } = require('lodash')

const { GITHUB, TOGGL } = require('../../config/credentials');
const github = require('../../handlers/github')
const toggl = require('../../handlers/toggl')
const { validateDatesFormat } = require('../helpers/inputValidation')
const { dataSyncs } = require('../../modules')
const apiModules = require('../../modules');
const apiModules = require('../../modules')

module.exports = {

Expand Down Expand Up @@ -132,7 +132,7 @@ module.exports = {
}
) || 0
return {
fromPayments: parseInt( totalPaidFromClient / totalIssues, 10),
fromPayments: parseInt(totalPaidFromClient / totalIssues, 10),
fromAllocations: parseInt(totalPaidFromAllocation / totalIssues, 10)
}
},
Expand Down
9 changes: 8 additions & 1 deletion api/schema/types/ContributorType.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = gql`
type Contributor {
id: Int!
toggl_id: Int
total_paid: Int!
name: String!
external_data_url: String
github_id: String
Expand All @@ -15,6 +14,9 @@ module.exports = gql`
permissions: [Permission]
timeEntries: [TimeEntry]
rates: [Rate]
"The following attributes are calculated and aren't on the database"
totalPaid: Int!
paidByCurrency: [TotalAllocatedByCurrency]
}
input CreateContributorInput {
Expand All @@ -38,6 +40,11 @@ module.exports = gql`
github_handle: String
}
type TotalAllocatedByCurrency {
amount: Int
currency: String
}
type Query {
checkSession: Contributor
getContributorById(id: Int!): Contributor
Expand Down
3 changes: 2 additions & 1 deletion api/schema/types/ProjectType.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ module.exports = gql`
toDate: String,
confirmedOnly: Boolean
): Int
"The total paid from the client"
totalPaid(
fromDate: String,
toDate: String
): Int # The total paid from the client, takes start date and ed date as attributes
): Int
totalIncurredPayments: Int # The total incurred not paid from the client
}
Expand Down
18 changes: 4 additions & 14 deletions src/components/AllocationAddForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const AllocationAddForm = (props) => {
rate_id: allocationRate.id
}
})
if (loadingNewAllocation) return <span>loading...</span>
if (loadingNewAllocation) return ''
else if (allocationCreated.errors) {
console.log('Error adding the allocation');
} else {
Expand Down Expand Up @@ -231,17 +231,6 @@ const AllocationAddForm = (props) => {
variables: {
contributorId: contributor ? contributor.id : null,
projectId: project ? project.id : null

}
}, {
query: GET_PAYMENT_ALLOCATIONS,
variables: {
paymentId: selectedPayment ? selectedPayment.id : null
}
}, {
query: GET_PAYMENT_TOTAL_ALLOCATED,
variables: {
paymentId: selectedPayment ? selectedPayment.id : null
}
}, {
query: GET_PROJECT_PAYMENTS,
Expand Down Expand Up @@ -370,8 +359,7 @@ const AllocationAddForm = (props) => {
const activeContributors = activeAllocations.map(a => {
return a.contributor
})

if (!rateCurrency) {
if (!rateCurrency && clientCurrency) {
setRateCurrency(clientCurrency)
}

Expand Down Expand Up @@ -495,6 +483,7 @@ const AllocationAddForm = (props) => {
<RateProratedMonthlyForm
clientCurrency={clientCurrency}
currentRate={mostRecentAllocation ? mostRecentAllocation.rate : null}
selectedPayment={selectedPayment}
setNewAllocationRate={setNewAllocationRate}
setCurrency={setRateCurrency}
startDate={moment(startDate)}
Expand All @@ -504,6 +493,7 @@ const AllocationAddForm = (props) => {
<RateMaxBudgetForm
clientCurrency={clientCurrency}
currentRate={mostRecentAllocation ? mostRecentAllocation.rate : null}
selectedPayment={selectedPayment}
setCurrency={setRateCurrency}
setNewAllocationRate={setNewAllocationRate}
startDate={moment(startDate)}
Expand Down
3 changes: 1 addition & 2 deletions src/components/AllocationClientSpecifics.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ const AllocationClientSpecifics = (props) => {
</Typography>
</Grid>
<Grid item xs={3}>
{
c.github_access_token &&
{c.github_access_token &&
<GitHubIcon color='secondary' fontSize='small'/>
}
</Grid>
Expand Down
Loading

0 comments on commit 4688271

Please sign in to comment.