92 lines
1.7 KiB
JavaScript
Executable File
92 lines
1.7 KiB
JavaScript
Executable File
const prisma = require('../../../helpers/db/db_connection');
|
|
|
|
class AdminRepository {
|
|
async create(adminData) {
|
|
return prisma.admin.create({
|
|
data: adminData
|
|
});
|
|
}
|
|
|
|
async findAll() {
|
|
return prisma.admin.findMany();
|
|
}
|
|
|
|
async findByEmail(email) {
|
|
return prisma.admin.findUnique({
|
|
where: { email }
|
|
});
|
|
}
|
|
|
|
async findById(id) {
|
|
return prisma.admin.findUnique({
|
|
where: { id: parseInt(id) }
|
|
});
|
|
}
|
|
|
|
async updateById(id, adminData) {
|
|
return prisma.admin.update({
|
|
where: { id: parseInt(id) },
|
|
data: adminData
|
|
});
|
|
}
|
|
|
|
async deleteById(id) {
|
|
return prisma.admin.delete({
|
|
where: { id: parseInt(id) }
|
|
});
|
|
}
|
|
|
|
async createMentor(mentorData) {
|
|
return prisma.admin.create({
|
|
data: {
|
|
...mentorData,
|
|
role: 'mentor',
|
|
},
|
|
});
|
|
}
|
|
|
|
async findMentors() {
|
|
return prisma.admin.findMany({
|
|
where: {
|
|
role: 'mentor',
|
|
}
|
|
});
|
|
}
|
|
|
|
async findMentorById(id) {
|
|
return prisma.admin.findFirst({
|
|
where: {
|
|
id: parseInt(id),
|
|
role: 'mentor',
|
|
},
|
|
});
|
|
}
|
|
|
|
async updateMentorById(id, mentorData) {
|
|
return prisma.admin.update({
|
|
where: {
|
|
id: parseInt(id),
|
|
},
|
|
data: mentorData,
|
|
});
|
|
}
|
|
|
|
async deleteMentorById(id) {
|
|
return prisma.admin.delete({
|
|
where: {
|
|
id: parseInt(id),
|
|
},
|
|
});
|
|
}
|
|
|
|
async countProjectsByAdminId(idAdmin) {
|
|
return prisma.project.count({
|
|
where: {
|
|
id_admin: parseInt(idAdmin),
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = new AdminRepository();
|