Skip to content

Commit

Permalink
Create the artStatus column for design notes (#9)
Browse files Browse the repository at this point in the history
* Remove ```expirationAt``` for database entries

* add index syncing

* Create the ```artIn``` column for design notes

* Add ```artStatus``` dropdown for design notes

* Update designNotes.js
  • Loading branch information
RandomY-2 authored Nov 28, 2022
1 parent 544a3e6 commit 2538a0e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 62 deletions.
30 changes: 11 additions & 19 deletions db/models/DesignNote.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
const mongoose = require('mongoose');

const EXPIRATION = 2;
// const EXPIRATION = 2;

const designNoteSchema = mongoose.Schema({
section: { type: String },
placement: { type: String },
slug: { type: String },
art: { type: String },
comments: { type: String },
date: { type: Date },
section: { type: String, default: "" },
placement: { type: String, default: "" },
slug: { type: String, default: "" },
art: { type: String, default: "" },
artStatus: { type: String, default: "" },
comments: { type: String, default: "" },
date: { type: Date, defautl: Date.now },
// You would think this would be a number
// but people often approximate or give
// ranges so
wordCount: { type: String },
status: { type: String },
referText: { type: String },
// expireAt: {
// type: Date,
// default: function () {
// const now = new Date();
// now.setDate(now.getDate() + EXPIRATION)
// return now;
// }
// }
wordCount: { type: String, default: "" },
status: { type: String, default: "" },
referText: { type: String, default: "" },
}, { timestamps: true, strict: false });
// designNoteSchema.index({ expireAt: 1 }, { expireAfterSeconds: 0 });

let DesignNote = mongoose.model('DesignNote', designNoteSchema);
module.exports = DesignNote;
10 changes: 0 additions & 10 deletions db/models/InstagramStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ const instagramStorySchema = mongoose.Schema({
figma: { type: String },
caption: { type: String },
date: { type: Date },
// expireAt: {
// type: Date,
// default: function () {
// const now = new Date();
// now.setDate(now.getDate() + EXPIRATION)
// return now;
// }
// }
}, { timestamps: true, strict: false });
// instagramStorySchema.index({ expireAt: 1 }, { expireAfterSeconds: 0 });

let InstagramStory = mongoose.model('InstagramStory', instagramStorySchema);
module.exports = InstagramStory;
9 changes: 0 additions & 9 deletions db/models/Modular.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ const EXPIRATION = 2;

const modularSchema = mongoose.Schema({
date: { type: Date },
// expireAt: {
// type: Date,
// default: function () {
// const now = new Date();
// now.setDate(now.getDate() + EXPIRATION)
// return now;
// }
// }
}, { timestamps: true, strict: false });
// modularSchema.index({ expireAt: 1 }, { expireAfterSeconds: 0 });

let Modular = mongoose.model('Modular', modularSchema);

Expand Down
15 changes: 4 additions & 11 deletions routes/api/designNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,28 @@ router.get('/:year-:month-:day', async (req, res) => {
});

router.post('/:year-:month-:day', async (req, res) => {
const { section, placement, slug, wordCount, art, status, comments, referText } = req.body;
const { section, placement, slug, wordCount, art, artStatus, status, comments, referText } = req.body;
const { year, month, day } = req.params;

const date = new Date(`${year}-${month}-${day}`);

const query = { placement, slug, section, wordCount, art, comments, status, referText, date };
// if (section == "inserts") {
// let expiration = new Date();
// expiration.setDate(expiration.getDate() + 14);
// query.expireAt = expiration;
// }
const query = { placement, slug, section, wordCount, art, artStatus, comments, status, referText, date };

await DesignNote.create(query, (err, note) => {
if (err) {
handleError(res);
}

res.json(note);
})
});

router.patch('/', async (req, res) => {
const { id, placement, slug, section, wordCount, art, comments, status, date, referText } = req.body;
const { id, placement, slug, section, wordCount, art, artStatus, comments, status, date, referText } = req.body;
// TODO this is so bad
const query = {};
placement && (query.placement = placement);
slug && (query.slug = slug);
wordCount && (query.wordCount = wordCount);
art && (query.art = art);
artStatus && (query.artStatus = artStatus);
comments && (query.comments = comments);
status && (query.status = status);
referText && (query.referText = referText);
Expand Down
43 changes: 31 additions & 12 deletions src/components/Home/DesignNotes/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,36 @@ export class DesignNotesForm extends React.Component {
}}
render={({ errors, status, touched, isSubmitting }) => (
<FormikForm>
{this.props.properties.map(f => (
<div key={f}>
<label htmlFor={f}>{f}:{' '}</label>
<Field
type="text"
name={f}
placeholder={config.designNotes.placeholders[f] || null}
/>
<ErrorMessage name={f} component="div" />
</div>
))}
{this.props.properties.map((f) => {
if (f === "artStatus") {
return (
<div key={f}>
<label htmlFor={f}>{f}:{' '}</label>
<Field
component="select"
name={f}
>
<option value="Art In">Art In</option>
<option value="Photo edited, no Camayak">Photo edited, no Camayak</option>
<option value="Waiting for courtesies">Waiting for courtesies</option>
</Field>
<ErrorMessage name={f} component="div" />
</div>
)
} else {
return (
<div key={f}>
<label htmlFor={f}>{f}:{' '}</label>
<Field
type="text"
name={f}
placeholder={config.designNotes.placeholders[f] || null}
/>
<ErrorMessage name={f} component="div" />
</div>
)
}
})}
{status && status.msg && <div>{status.msg}</div>}
<button className="primary" type="submit" disabled={isSubmitting}>
<span className="semibold">+</span> Create
Expand All @@ -68,4 +87,4 @@ export class DesignNotesForm extends React.Component {
</div>
)
}
}
}
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = {
},
designNotes: {
sections: ["news", "opinion", "sports", "arts", "inserts"],
properties: ["placement", "slug", "art", "wordCount", "comments", "status", "referText"],
properties: ["placement", "slug", "art", "artStatus", "wordCount", "comments", "status", "referText"],
placeholders: {
"comments": "refers/flags/etc."
}
Expand Down

0 comments on commit 2538a0e

Please sign in to comment.