Some changes
This commit is contained in:
43
server/src/models/appointment.js
Normal file
43
server/src/models/appointment.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import mongoose from 'mongoose';
|
||||||
|
import timestamps from 'mongoose-timestamp';
|
||||||
|
import { composeWithMongoose } from 'graphql-compose-mongoose';
|
||||||
|
|
||||||
|
export const AppointmentSchema = new mongoose.Schema(
|
||||||
|
{
|
||||||
|
user: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: 'User',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
timeStart: {
|
||||||
|
type: Date,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
timeEnd: {
|
||||||
|
type: Date,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
collection: 'appointment',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
AppointmentSchema.plugin(timestamps);
|
||||||
|
|
||||||
|
AppointmentSchema.index({ createdAt: 1, updatedAt: 1 });
|
||||||
|
|
||||||
|
export const Appointment = mongoose.model('Appointment', AppointmentSchema);
|
||||||
|
export const AppointmentTC = composeWithMongoose(Appointment);
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import timestamps from 'mongoose-timestamp';
|
|
||||||
import { composeWithMongoose } from 'graphql-compose-mongoose';
|
|
||||||
|
|
||||||
export const TaskSchema = new mongoose.Schema(
|
|
||||||
{
|
|
||||||
user: {
|
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
|
||||||
ref: 'User',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
task: {
|
|
||||||
type: String,
|
|
||||||
trim: true,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: String,
|
|
||||||
trim: true,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
collection: 'tasks',
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
TaskSchema.plugin(timestamps);
|
|
||||||
|
|
||||||
TaskSchema.index({ createdAt: 1, updatedAt: 1 });
|
|
||||||
|
|
||||||
export const Task = mongoose.model('Task', TaskSchema);
|
|
||||||
export const TaskTC = composeWithMongoose(Task);
|
|
||||||
@@ -4,18 +4,33 @@ import { composeWithMongoose } from 'graphql-compose-mongoose';
|
|||||||
|
|
||||||
export const UserSchema = new mongoose.Schema(
|
export const UserSchema = new mongoose.Schema(
|
||||||
{
|
{
|
||||||
name: {
|
firstName: {
|
||||||
type: String,
|
type: String,
|
||||||
trim: true,
|
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
lastName: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
password: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
email: {
|
email: {
|
||||||
type: String,
|
type: String,
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
trim: true,
|
|
||||||
unique: true,
|
unique: true,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isActive: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: 1
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
collection: 'users',
|
collection: 'users',
|
||||||
|
|||||||
51
server/src/schema/appointment.js
Normal file
51
server/src/schema/appointment.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { Appointment, AppointmentTC } from '../models/appointment.js';
|
||||||
|
|
||||||
|
async function feed(parent, args, context, info) {
|
||||||
|
|
||||||
|
const where = args.filter
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ title: { contains: args.filter } },
|
||||||
|
{ description: { contains: args.filter } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
console.log(context.mongo);
|
||||||
|
const appointments = await context.mongo.appointment.findMany({
|
||||||
|
where,
|
||||||
|
skip: args.skip,
|
||||||
|
take: args.take,
|
||||||
|
orderBy: args.orderBy
|
||||||
|
});
|
||||||
|
|
||||||
|
const count = await context.mongo.appointment.count({ where });
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: 'main-feed',
|
||||||
|
appointments,
|
||||||
|
count
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppointmentQuery = {
|
||||||
|
appointmentById: AppointmentTC.getResolver('findById'),
|
||||||
|
appointmentByIds: AppointmentTC.getResolver('findByIds'),
|
||||||
|
appointmentOne: AppointmentTC.getResolver('findOne'),
|
||||||
|
appointmentMany: AppointmentTC.getResolver('findMany'),
|
||||||
|
appointmentCount: AppointmentTC.getResolver('count'),
|
||||||
|
appointmentConnection: AppointmentTC.getResolver('connection'),
|
||||||
|
appointmentPagination: AppointmentTC.getResolver('pagination'),
|
||||||
|
};
|
||||||
|
|
||||||
|
const AppointmentMutation = {
|
||||||
|
appointmentCreateOne: AppointmentTC.getResolver('createOne'),
|
||||||
|
appointmentCreateMany: AppointmentTC.getResolver('createMany'),
|
||||||
|
appointmentUpdateById: AppointmentTC.getResolver('updateById'),
|
||||||
|
appointmentUpdateOne: AppointmentTC.getResolver('updateOne'),
|
||||||
|
appointmentUpdateMany: AppointmentTC.getResolver('updateMany'),
|
||||||
|
appointmentRemoveById: AppointmentTC.getResolver('removeById'),
|
||||||
|
appointmentRemoveOne: AppointmentTC.getResolver('removeOne'),
|
||||||
|
appointmentRemoveMany: AppointmentTC.getResolver('removeMany'),
|
||||||
|
};
|
||||||
|
|
||||||
|
export { AppointmentQuery, AppointmentMutation };
|
||||||
@@ -5,16 +5,16 @@ import db from '../utils/db.js';
|
|||||||
const schemaComposer = new SchemaComposer();
|
const schemaComposer = new SchemaComposer();
|
||||||
|
|
||||||
import { UserQuery, UserMutation } from './user.js';
|
import { UserQuery, UserMutation } from './user.js';
|
||||||
import { TaskQuery, TaskMutation } from './task.js';
|
import { AppointmentQuery, AppointmentMutation } from './appointment.js';
|
||||||
|
|
||||||
schemaComposer.Query.addFields({
|
schemaComposer.Query.addFields({
|
||||||
...UserQuery,
|
...UserQuery,
|
||||||
...TaskQuery,
|
...AppointmentQuery,
|
||||||
});
|
});
|
||||||
|
|
||||||
schemaComposer.Mutation.addFields({
|
schemaComposer.Mutation.addFields({
|
||||||
...UserMutation,
|
...UserMutation,
|
||||||
...TaskMutation,
|
...AppointmentMutation,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default schemaComposer.buildSchema();
|
export default schemaComposer.buildSchema();
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { Task, TaskTC } from '../models/task.js';
|
|
||||||
|
|
||||||
const TaskQuery = {
|
|
||||||
taskById: TaskTC.getResolver('findById'),
|
|
||||||
taskByIds: TaskTC.getResolver('findByIds'),
|
|
||||||
taskOne: TaskTC.getResolver('findOne'),
|
|
||||||
taskMany: TaskTC.getResolver('findMany'),
|
|
||||||
taskCount: TaskTC.getResolver('count'),
|
|
||||||
taskConnection: TaskTC.getResolver('connection'),
|
|
||||||
taskPagination: TaskTC.getResolver('pagination'),
|
|
||||||
};
|
|
||||||
|
|
||||||
const TaskMutation = {
|
|
||||||
taskCreateOne: TaskTC.getResolver('createOne'),
|
|
||||||
taskCreateMany: TaskTC.getResolver('createMany'),
|
|
||||||
taskUpdateById: TaskTC.getResolver('updateById'),
|
|
||||||
taskUpdateOne: TaskTC.getResolver('updateOne'),
|
|
||||||
taskUpdateMany: TaskTC.getResolver('updateMany'),
|
|
||||||
taskRemoveById: TaskTC.getResolver('removeById'),
|
|
||||||
taskRemoveOne: TaskTC.getResolver('removeOne'),
|
|
||||||
taskRemoveMany: TaskTC.getResolver('removeMany'),
|
|
||||||
};
|
|
||||||
|
|
||||||
export { TaskQuery, TaskMutation };
|
|
||||||
Reference in New Issue
Block a user