File tree Expand file tree Collapse file tree 3 files changed +131
-38
lines changed Expand file tree Collapse file tree 3 files changed +131
-38
lines changed Original file line number Diff line number Diff line change 1+ import connector from "#models/databaseUtil" ;
2+
3+ const studentBankSchema = {
4+ uid : {
5+ type : String ,
6+ required : true ,
7+ unique : true ,
8+ } ,
9+ bankName : {
10+ type : String ,
11+ required : true ,
12+ minLength : 7 ,
13+ } ,
14+ bankAccount : {
15+ type : String ,
16+ required : true ,
17+ unique : true ,
18+ } ,
19+ bankBranch : {
20+ type : String ,
21+ required : true ,
22+ } ,
23+ bankIfsc : {
24+ type : String ,
25+ required : true ,
26+ maxLength : 11 ,
27+ minLength : 11 ,
28+ } ,
29+ bankMicr : {
30+ type : String ,
31+ required : true ,
32+ maxLength : 9 ,
33+ minLength : 9 ,
34+ } ,
35+ } ;
36+
37+ const StudentBank = connector . model ( "Student bank" , studentBankSchema ) ;
38+
39+ async function create ( studentBankData ) {
40+ const {
41+ uid,
42+ bankName,
43+ bankAccount,
44+ bankBranch,
45+ bankIfsc,
46+ bankMicr,
47+ } = studentBankData ;
48+
49+ const stdBank = new StudentBank ( {
50+ uid,
51+ bankName,
52+ bankAccount,
53+ bankBranch,
54+ bankIfsc,
55+ bankMicr,
56+ } ) ;
57+
58+ const stdBankDoc = await stdBank . save ( ) ;
59+ return stdBankDoc ;
60+ }
61+
62+ async function read ( filter , limit = 1 ) {
63+ const stdBankDoc = studentBankSchema . find ( filter ) . limit ( limit ) ;
64+ return stdBankDoc ;
65+ }
66+
67+ async function update ( filter , updateObject , options = { multi : true } ) {
68+ const updateResult = await studentBankSchema . updateMany (
69+ filter ,
70+ { $set : updateObject } ,
71+ options ,
72+ ) ;
73+ return updateResult . acknowledged ;
74+ }
75+
76+ async function remove ( stdBankId ) {
77+ const deleteResult = await studentBankSchema . deleteMany ( stdBankId ) ;
78+ return deleteResult . acknowledged ;
79+ }
80+
81+ export default {
82+ create,
83+ read,
84+ update,
85+ remove,
86+ } ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import StudentBank from "#models/student/stdBank" ;
2+ import databaseError from "#error/database" ;
3+
4+ export async function createStudentBank (
5+ uid ,
6+ bankName ,
7+ bankAccount ,
8+ bankBranch ,
9+ bankIfsc ,
10+ bankMicr ,
11+ ) {
12+ const newStudentBank = await StudentBank . create ( {
13+ uid,
14+ bankName,
15+ bankAccount,
16+ bankBranch,
17+ bankIfsc,
18+ bankMicr,
19+ } ) ;
20+ if ( newStudentBank . uid === uid ) {
21+ return newStudentBank ;
22+ }
23+ throw new databaseError . DataEntryError ( "student bank" ) ;
24+ }
25+
26+ export async function updateStudentBankById ( id , data ) {
27+ const updated = await StudentBank . update ( { _id : id } , data ) ;
28+ if ( updated ) {
29+ return updated ;
30+ }
31+ throw new databaseError . DataEntryError ( "student bank" ) ;
32+ }
33+
34+ export async function studentBankList ( filter ) {
35+ const studentBank = await StudentBank . read ( filter , 0 ) ;
36+ return studentBank ;
37+ }
38+
39+ export async function deleteStudentBankById ( studentBankId ) {
40+ const deleted = await StudentBank . remove ( { _id : studentBankId } ) ;
41+ if ( deleted ) {
42+ return deleted ;
43+ }
44+ throw new databaseError . DataDeleteError ( "student bank" ) ;
45+ }
You can’t perform that action at this time.
0 commit comments