Skip to content

Commit

Permalink
tings
Browse files Browse the repository at this point in the history
  • Loading branch information
lnart committed Apr 4, 2024
1 parent f8c54cf commit 2e85bce
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
dockerfile: Dockerfile
environment:
PORT: ${PORT}
DB_CONNECTION_STRING: ${DB_CONNECTION_STRING}
DB_CONNECTION_STRING: ${CLOUD_DB_CONNECTION_STRING}
BASE_URL: ${BASE_URL}
MQTT_CONNECT_STRING: ${MQTT_CONNECT_STRING}
MQTT_USERNAME: ${MQTT_USERNAME}
Expand Down
68 changes: 57 additions & 11 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"mongodb": "^6.5.0",
"mongoose": "^8.2.0",
"mqtt": "^5.3.6",
"nodemon": "^3.1.0",
Expand Down
9 changes: 3 additions & 6 deletions src/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import mongoose from "mongoose";
import { config } from "dotenv";
import { mongoDbPreferences } from "./mongoDbPreferences";

config();

export async function connectToDb() {
if (process.env.DB_CONNECTION_STRING) {
if (process.env.CLOUD_DB_CONNECTION_STRING) {
const db = await mongoose
.connect(
`${process.env.DB_CONNECTION_STRING}/${mongoDbPreferences.databaseName}`,
)
.connect(`${process.env.CLOUD_DB_CONNECTION_STRING}`)
.then(() => console.log(`Successfully connected to MongoDB`))
.catch((error) => console.error(`Comnnection error: ${error}`));
.catch((error) => console.error(`Connection error: ${error}`));
return db;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/db/mongoDbPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { config } from "dotenv";
config();

export enum mongoDbPreferences {
databaseName = "dryAger",
dryAgerCollection = "DryAgers",
usersCollection = "Users",
recordsCollection = "Records",
recipesColleciton = "Recipes",
databaseName = "MeatMatureDB",
dryAgerCollection = "dryAgers",
usersCollection = "users",
recordsCollection = "records",
recipesColleciton = "recipes",
}
19 changes: 9 additions & 10 deletions src/db/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ export const userSchema = new mongoose.Schema({
dryAgerIds: [{ type: mongoose.Schema.Types.ObjectId, ref: "DryAger" }],
});

export const User = mongoose.model("User", userSchema);
export const User = mongoose.model("user", userSchema);
export type UserType = typeof userSchema;

export const dryAgerSchema = new mongoose.Schema({
userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true },
userId: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
name: { type: String, required: true },
model: String,
status: {
light: { type: String, enum: ["on", "off"], default: "off" },
fan: { type: String, enum: ["on", "off"], default: "off" },
},
// Assuming records are referenced in the Records collection, not stored directly
});

export const DryAger = mongoose.model("DryAger", dryAgerSchema);
export const DryAger = mongoose.model("dryAger", dryAgerSchema);

export const recordSchema = new mongoose.Schema({
dryAgerId: {
type: mongoose.Schema.Types.ObjectId,
ref: "DryAger",
ref: "dryAger",
required: true,
},
date: { type: Date, default: Date.now },
Expand All @@ -38,21 +37,21 @@ export const recordSchema = new mongoose.Schema({

recordSchema.index({ dryAgerId: 1, date: -1 });

export const Record = mongoose.model("Record", recordSchema);
export const Record = mongoose.model("record", recordSchema);

export const recipeSchema = new mongoose.Schema({
userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true },
userId: { type: mongoose.Schema.Types.ObjectId, ref: "user", required: true },
name: { type: String, required: true },
description: String,
notes: String,
dryAgerId: {
type: mongoose.Schema.Types.ObjectId,
ref: "DryAger",
ref: "dryAger",
required: true,
},
startDate: { type: Date, required: true },
endDate: { type: Date, required: true },
relatedRecords: [{ type: mongoose.Schema.Types.ObjectId, ref: "Record" }],
relatedRecords: [{ type: mongoose.Schema.Types.ObjectId, ref: "record" }],
});

export const Recipe = mongoose.model("Recipe", recipeSchema);
export const Recipe = mongoose.model("recipe", recipeSchema);
6 changes: 3 additions & 3 deletions src/endPoints/users/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export const userRouter = router({
return res;
}),

test: publicProcedure.query(()=>{
return 'success'
})
test: publicProcedure.query(() => {
return "success";
}),
});

export type userRouter = typeof userRouter;
15 changes: 0 additions & 15 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ export type EditUser = {
email?: string;
};

export const testSchema = z
.object({
username: z.string().optional(),
id: z.string().optional(),
})
.refine(
(data) => {
// Ensure exactly one of the properties is provided
return (data.username && !data.id) || (!data.username && data.id);
},
{
message: "Either 'username' or 'id' must be provided, but not both.",
},
);

export type DryAger = {
_id: string;
userId: string; // Reference to User
Expand Down

0 comments on commit 2e85bce

Please sign in to comment.