@@ -23,25 +23,45 @@ export class PopulateProblems {
2323 const rowAlreadyExists : boolean = await this . rowAlreadyExists ( problem ) ;
2424
2525 if ( rowAlreadyExists ) {
26+ await this . updateProblem ( problem ) ;
2627 return ;
2728 }
2829
30+ await this . saveProblem ( problem ) ;
31+ }
32+
33+ private static async rowAlreadyExists ( problem : LeetcodeProblem ) : Promise < boolean > {
34+ return await Problems . exists ( { problemId : problem . stat . question_id } ) !== null ;
35+ }
36+
37+ private static async updateProblem ( problem : LeetcodeProblem ) : Promise < void > {
38+ Problems . findOneAndUpdate ( { problemId : problem . stat . question_id } , {
39+ problemId : problem . stat . question_id ,
40+ title : problem . stat . question__title ,
41+ titleSlug : problem . stat . question__title_slug ,
42+ isPremium : problem . paid_only ,
43+ difficulty : problem . difficulty . level ,
44+ frontEndId : problem . stat . frontend_question_id ,
45+ numSubmitted : problem . stat . total_submitted ,
46+ numAccepted : problem . stat . total_acs
47+ } ) ;
48+ }
49+
50+ private static async saveProblem ( problem : LeetcodeProblem ) : Promise < void > {
2951 const p : IProblem = await Problems . create ( {
3052 problemId : problem . stat . question_id ,
3153 title : problem . stat . question__title ,
3254 titleSlug : problem . stat . question__title_slug ,
3355 isPremium : problem . paid_only ,
3456 difficulty : problem . difficulty . level ,
35- frontEndId : problem . stat . frontend_question_id
57+ frontEndId : problem . stat . frontend_question_id ,
58+ numSubmitted : problem . stat . total_submitted ,
59+ numAccepted : problem . stat . total_acs
3660 } ) ;
3761
3862 await p . save ( ) ;
3963 }
4064
41- private static async rowAlreadyExists ( problem : LeetcodeProblem ) : Promise < boolean > {
42- return await Problems . exists ( { problemId : problem . stat . question_id } ) !== null ;
43- }
44-
4565 public static get problems ( ) : Promise < LeetcodeProblem [ ] | null > | null {
4666 if ( this . data === null ) {
4767 this . data = ProblemExtractor . problems ;
0 commit comments