Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ultish committed Aug 19, 2020
1 parent 978134d commit 183e02b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ sequelize.sync({ force: eraseDatabaseOnSync }).then(async () => {
}
});

httpServer.listen({ port: 9998 }, () => {
console.log("Apollo Server on http://localhost:9998/graphql");
console.log("server port", process.env.SERVER_PORT);
const port = process.env.SERVER_PORT || 9998;
httpServer.listen({ port: port }, () => {
console.log(`Apollo Server on http://localhost:${port}/graphql`);
});

const createUsersWithMessages = async (date) => {
Expand Down
2 changes: 1 addition & 1 deletion src/models/timeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const timeBlock = (sequelize, DataTypes) => {
indexes: [
{
unique: true,
fields: ["startTime", "trackedtaskId"],
fields: ["startTime", "trackedtaskId", "userId"],
},
{
fields: ["trackedtaskId"],
Expand Down
35 changes: 18 additions & 17 deletions src/resolvers/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
isTrackedDayOwner,
isTrackedTaskOwner,
} from "./authorization";
import { ForbiddenError } from "apollo-server";
import { ForbiddenError, UserInputError } from "apollo-server";

import pubsub, { EVENTS } from "../subscriptions";
import chargecode from "../models/chargecode";
Expand Down Expand Up @@ -150,7 +150,8 @@ const updateTimesheet = async (
const timeBlockDate = timeBlock.startTime;

// for a given date of the timeBlock, we can have overlapping timeBlocks.
// this affects the amount each block increments/decrements for all
// this affects the amount each block increments/d
// ecrements for all
// timeCharges at this time slot

// fetch timeBlocks for a given date
Expand Down Expand Up @@ -546,6 +547,19 @@ export default {
createTrackedDay: combineResolvers(
isAuthenticated,
async (parent, { date, mode }, { me, models }) => {
const existing = await models.TrackedDay.findAll({
where: {
date: new Date(date),
userId: me.id,
},
});
debugger;
if (existing.length) {
throw new UserInputError("Tracked Day already exists", {
trackeddayId: existing[0].id,
});
}

const trackedDay = await models.TrackedDay.create({
date: new Date(date),
mode,
Expand Down Expand Up @@ -705,13 +719,7 @@ export default {
userId: me.id,
});

await updateTimesheet(
models,
me,
trackedDay,
// trackedTask,
timeBlock
);
await updateTimesheet(models, me, trackedDay, timeBlock);

return timeBlock;
} else {
Expand Down Expand Up @@ -761,14 +769,7 @@ export default {
trackedTask.trackeddayId
);

await updateTimesheet(
models,
me,
trackedDay,
// trackedTask,
timeBlock,
false
);
await updateTimesheet(models, me, trackedDay, timeBlock, false);

const result = await models.TimeBlock.destroy({ where: { id } });
if (result) {
Expand Down

0 comments on commit 183e02b

Please sign in to comment.