-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes and added last updated feature
- Loading branch information
Showing
31 changed files
with
523 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateRecord = exports.getRecord = void 0; | ||
const records_1 = __importDefault(require("../models/records")); | ||
const getRecord = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { card } = req.params; | ||
try { | ||
const updatedRecord = yield records_1.default.findOne({ card }); | ||
if (updatedRecord === null) { | ||
res.status(404); | ||
} | ||
res.status(200).json(updatedRecord); | ||
} | ||
catch (error) { | ||
next(error); | ||
} | ||
}); | ||
exports.getRecord = getRecord; | ||
const updateRecord = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { card } = req.params; | ||
try { | ||
const record = yield records_1.default.findOneAndUpdate({ card: card }, req.body); | ||
if (record === null) { | ||
res.status(404); | ||
} | ||
const updatedRecord = yield records_1.default.findOne({ card }); | ||
if (updatedRecord === null) { | ||
res.status(404); | ||
} | ||
res.status(200).json(updatedRecord); | ||
} | ||
catch (error) { | ||
next(error); | ||
} | ||
}); | ||
exports.updateRecord = updateRecord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const mongoose_1 = require("mongoose"); | ||
const recordsSchema = new mongoose_1.Schema({ | ||
card: { type: String, required: true }, | ||
date: { type: String, required: true }, | ||
}); | ||
exports.default = (0, mongoose_1.model)("Editrecords", recordsSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const express_1 = __importDefault(require("express")); | ||
const RecordsController = __importStar(require("../controllers/records")); | ||
const RecordsValidator = __importStar(require("../validators/records")); | ||
const router = express_1.default.Router(); | ||
router.put("/:card", RecordsValidator.updateRecord, RecordsController.updateRecord); | ||
router.get("/:card", RecordsController.getRecord); | ||
exports.default = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateRecord = void 0; | ||
const express_validator_1 = require("express-validator"); | ||
const makeIDValidator = () => (0, express_validator_1.body)("_id") | ||
.exists() | ||
.withMessage("_id is required") | ||
.bail() | ||
.isMongoId() | ||
.withMessage("_id must be a MongoDB object ID"); | ||
const makeCardValidator = () => (0, express_validator_1.body)("card") | ||
.exists() | ||
.withMessage("card is required") | ||
.bail() | ||
.isString() | ||
.withMessage("card must be a string") | ||
.bail() | ||
.notEmpty() | ||
.withMessage("card cannot be empty"); | ||
const makeDateValidator = () => (0, express_validator_1.body)("date") | ||
.exists() | ||
.withMessage("date is required") | ||
.bail() | ||
.isString() | ||
.withMessage("date must be a string") | ||
.bail() | ||
.notEmpty() | ||
.withMessage("date cannot be empty"); | ||
exports.updateRecord = [makeIDValidator(), makeCardValidator(), makeDateValidator()]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { RequestHandler } from "express"; | ||
import RecordModel from "src/models/records"; | ||
|
||
export const getRecord: RequestHandler = async (req, res, next) => { | ||
const { card } = req.params; | ||
try { | ||
const updatedRecord = await RecordModel.findOne({ card }); | ||
if (updatedRecord === null) { | ||
res.status(404); | ||
} | ||
|
||
res.status(200).json(updatedRecord); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const updateRecord: RequestHandler = async (req, res, next) => { | ||
const { card } = req.params; | ||
|
||
try { | ||
const record = await RecordModel.findOneAndUpdate({ card: card }, req.body); | ||
|
||
if (record === null) { | ||
res.status(404); | ||
} | ||
const updatedRecord = await RecordModel.findOne({ card }); | ||
if (updatedRecord === null) { | ||
res.status(404); | ||
} | ||
|
||
res.status(200).json(updatedRecord); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.