v1.0.0 #28
|
@ -1,4 +1,4 @@
|
||||||
version: '3'
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
mongodb:
|
mongodb:
|
||||||
|
|
|
@ -23,7 +23,11 @@ class ImageController {
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error instanceof mongo.MongoServerError && error.code === 11000) {
|
if (error instanceof mongo.MongoServerError && error.code === 11000) {
|
||||||
// Should return 409 Conflict for existing urls
|
// Should return 409 Conflict for existing urls
|
||||||
res.status(409).json({ error: `the image with URL ${error.keyValue.url} already exists` });
|
res
|
||||||
|
.status(409)
|
||||||
|
.json({
|
||||||
|
error: `the image with URL ${error.keyValue.url} already exists`,
|
||||||
|
});
|
||||||
} else if (error instanceof mongoose.Error.ValidationError) {
|
} else if (error instanceof mongoose.Error.ValidationError) {
|
||||||
// Should return 400 Bad request for invalid requests
|
// Should return 400 Bad request for invalid requests
|
||||||
res.status(400).json({ error: error.message });
|
res.status(400).json({ error: error.message });
|
||||||
|
|
|
@ -15,8 +15,7 @@ app.get("/", (_, res) => {
|
||||||
|
|
||||||
app.get("/images", imageController.getAllImages);
|
app.get("/images", imageController.getAllImages);
|
||||||
app.post("/images", authControler.authorize, imageController.addImage);
|
app.post("/images", authControler.authorize, imageController.addImage);
|
||||||
app.post("/login", authControler.login)
|
app.post("/login", authControler.login);
|
||||||
|
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
// Set the default port to 8080, or use the PORT environment variable
|
// Set the default port to 8080, or use the PORT environment variable
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import mongoose, { Document } from "mongoose";
|
import mongoose, { Document } from "mongoose";
|
||||||
|
|
||||||
export interface Auth extends Document {
|
export interface Auth extends Document {
|
||||||
app: String,
|
app: String;
|
||||||
secret: String
|
secret: String;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthSchema = new mongoose.Schema({
|
const AuthSchema = new mongoose.Schema({
|
||||||
|
|
|
@ -9,18 +9,18 @@ export interface Image extends Document {
|
||||||
const ImageSchema = new mongoose.Schema({
|
const ImageSchema = new mongoose.Schema({
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: {
|
enum: {
|
||||||
values: ["consumed", "unavailable", "available"],
|
values: ["consumed", "unavailable", "available"],
|
||||||
},
|
},
|
||||||
required: true
|
required: true,
|
||||||
},
|
},
|
||||||
tags: {
|
tags: {
|
||||||
type: [String]
|
type: [String],
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default mongoose.model<Image>('images', ImageSchema);
|
export default mongoose.model<Image>("images", ImageSchema);
|
||||||
|
|
|
@ -41,7 +41,6 @@ describe("GET /images works properly", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("POST /images works properly", () => {
|
describe("POST /images works properly", () => {
|
||||||
|
|
||||||
it("should return 401 for unauthenticated requests", async () => {
|
it("should return 401 for unauthenticated requests", async () => {
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post("/images")
|
.post("/images")
|
||||||
|
|
|
@ -19,4 +19,3 @@ describe("/login", async () => {
|
||||||
expect(res.status).toBe(403);
|
expect(res.status).toBe(403);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue