const mongoose = require('mongoose');
const api = {};
api.checkId = () => (req, res, next) => {
if (!mongoose.Types.ObjectId.isValid(req.params.id)) {
next(new Error(404, "Wrong project id"));
} else {
next();
}
};
api.get = (Project) => (req, res, next) => {
Project.findById(req.params.id)
.then(project => res.json(project));
};
api.update = (Project) => (req, res, next) => {
Project.findByIdAndUpdate(req.params.id, req.body, { new: true })
.then(project => res.json(project));
};
api.delete = (Project) => (req, res, next) => {
Project.findByIdAndRemove(req.params.id)
.then(project => res.json(project));
};
api.notImplement = () => (req, res, next) => {
next(new Error("not implemented!"));
};
api.all = (Project) => (req, res, next) => {
Project.find()
.sort({ date: -1 })
.then(projects => res.json(projects))
.catch(next);
};
api.create = (Project) => (req, res, next) => {
const newProject = new Project({
name: req.body.name,
description: req.body.description,
slides: []
});
newProject
.save()
.then(project => res.json(project))
.catch(next);
};
module.exports = api;
const router = require('express').Router();
const api = require('../api/project')
// Project model
const Project = require('../models/project');
// @routes
router
.route('/:id')
.all(api.checkId())
.get(api.get(Project))
.put(api.update(Project))
.delete(api.delete(Project))
.post(api.notImplement());
router.get('/', api.all(Project));
router.post('/', api.create(Project));
module.exports = router;
res.status(404).json({message: 'Project not found'}).end()
data () {
return {
currentPanel: PANELS.PANEL_0,
PANELS
}
}
var entries = getEntries('./source/pages/', '@(js|vue)'); // Obtain entry js file
if ( has_term( $cat_product_ID, 'product_cat', $product->get_id() ) ) {
...
}
<?php
global $post;
$posts = get_posts(array('numberposts' => -1,));
foreach($posts as $item){ setup_postdata($item);
echo $item->post_title;
echo ($item->ID === $post->ID) ? 'Текущий пост' : '';
}
wp_reset_postdata();
define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');
git init
git add filename.js
atom filename.js
git status
function isWorkHour(start, end) {
var date = new Date(),
hours = date.getHours();
return (hours > start && hours <= end) ? true : false;
}
function padNumber(number, pad) {
var N = Math.pow(10, pad);
return number < N ? ("" + (N + number)).slice(1) : "" + number;
}
function getRemainingTime(newData, oldData) {
var diff = (oldData.getTime() - newData.getTime()) / 1000;
var hrs = parseInt(diff / 3600);
diff = diff % 3600;
var minutes = parseInt(diff / 60);
return {
hrs: padNumber( Math.abs(hrs), 2 ),
mnt: padNumber( Math.abs(minutes), 2 )
}
}
function workHourse(start, end) {
var timer = document.getElementById('timer'),
text;
if ( isWorkHour(start, end) ) {
var time,
date = new Date(),
oldData = new Date();
oldData.setHours(end);
oldData.setMinutes(0);
oldData.setSeconds(0);
time = getRemainingTime(date, oldData);
str = 'Осталось работать: ' + time.hrs + ':' + time.mnt;
} else {
str = 'Рабочие часы закончились';
}
text = document.createTextNode(str);
timer.innerHTML = '';
timer.appendChild(text);
(setTimeout(function () {
workHourse(start, end);
}, 1000))(start, end);
}
workHourse(10, 12);