Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pilas-bloques-models

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pilas-bloques-models - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

src/context.ts

8

index.ts

@@ -1,6 +0,8 @@

import Solution from "./src/solution";
import { Challenge } from "./src/challenge";
import { Context } from "./src/context";
import { Solution } from "./src/solution";
import { User } from "./src/user";
import { DocumentOf, Nullable, SESSION_FIELDS } from "./src/utils";
import { DocumentOf, Nullable } from "./src/utils";
export { Solution, DocumentOf, Nullable, SESSION_FIELDS, User }
export { Solution, DocumentOf, Nullable, Context, User, Challenge }
{
"name": "pilas-bloques-models",
"version": "1.0.8",
"version": "1.0.9",
"description": "Pilas Bloques models for development.",

@@ -5,0 +5,0 @@ "main": "index.ts",

@@ -1,36 +0,24 @@

// import * as mongoose from 'mongoose'
// import { SESSION_FIELDS, DocumentOf } from './utils'
// import { SolutionDoc } from './solution'
// const Schema = mongoose.Schema
import { prop, getModelForClass, Severity, modelOptions, Ref, ReturnModelType } from '@typegoose/typegoose'
import * as mongoose from 'mongoose'
import { Context } from './context'
import { Solution } from './solution'
// const CHALLENGE_FIELDS = {
// challengeId: {
// type: Schema.Types.Mixed,
// required: true
// },
// firstSolution: {
// type: Schema.Types.ObjectId
// },
// session: SESSION_FIELDS
// }
@modelOptions({ options: { allowMixed: Severity.ALLOW } })
export class Challenge {
@prop({ required: true, index: true })
challengeId: mongoose.Schema.Types.Mixed
@prop({ ref: () => Solution })
firstSolution: Ref<Solution>
@prop()
context: Context
// const repository = {
// setFirstSolution: async function (this: mongoose.Model<ChallengeDoc>, challengeId: any, sessionId: any, solution: SolutionDoc) {
// const challenge = await this.findOne({ challengeId, 'session.id': sessionId }).sort({ 'session.timestamp': -1 })
// if (challenge && !challenge.firstSolution) {
// challenge.firstSolution = solution
// return challenge.save()
// }
// }
// }
public static async setFirstSolution(this: ReturnModelType<typeof Challenge>, challengeId: any, contextId: any, solution: Solution) {
const challenge = await this.findOne({ challengeId, 'context.id': contextId }).sort({ 'context.timestamp': -1 })
if (challenge && !challenge.firstSolution) {
challenge.firstSolution = solution
return challenge.save()
}
}
}
// const ChallengeSchema = new Schema(CHALLENGE_FIELDS)
// ChallengeSchema.statics = repository
// interface ChallengeDoc extends DocumentOf<typeof CHALLENGE_FIELDS> {
// firstSolution?: SolutionDoc
// }
// type ChallengeModel = mongoose.Model<ChallengeDoc> & typeof repository
// export default mongoose.model<ChallengeDoc, ChallengeModel>('Challenge', ChallengeSchema)
export default getModelForClass<typeof Challenge>(Challenge)
import { prop, getModelForClass, Severity, modelOptions, Ref } from '@typegoose/typegoose'
import { Schema } from 'mongoose'
import { Context } from './context'
import { User } from './user'
@modelOptions({ options: { allowMixed: Severity.ALLOW } })

@@ -14,9 +14,30 @@ export class Solution {

@prop({ required: true })
staticAnalysis: Schema.Types.Mixed
ast: Schema.Types.Mixed
@prop({ required: true })
turboModeOn: boolean
@prop({ required: true })
timestamp: Date
@prop()
executionResult: Schema.Types.Mixed
@prop({ ref: () => User })
user: Ref<User>
executionResult: {
isTheProblemSolved: {
type: Boolean
},
stoppedByUser: {
type: Boolean
},
error: {
type: Schema.Types.Mixed
},
}
@prop()
staticAnalysis: {
couldExecute: {
type: Boolean,
required: true
}
}
@prop()
context: Context
}
export default getModelForClass<typeof Solution>(Solution)

@@ -38,7 +38,16 @@ import { prop, getModelForClass, ReturnModelType, Severity, modelOptions } from '@typegoose/typegoose'

/**
*
* @param username is the non-standarized username (could have UpperCase letters)
* @returns the user from the DB
*/
static findByUsername(this: ReturnModelType<typeof User>, username: string) {
return this.findOne({ 'username': username })
return this.findOne({ 'username': this.standarizeUsername(username) })
}
static standarizeUsername(this: ReturnModelType<typeof User>, username: string) {
return username.toLowerCase()
}
}
export default getModelForClass<typeof User>(User)
import * as mongoose from 'mongoose'
const Schema = mongoose.Schema
import { Schema } from 'mongoose'
export const SESSION_FIELDS = {
online: {
type: Boolean,
required: true
},
browserId: {
type: Schema.Types.Mixed,
required: true
},
id: {
type: Schema.Types.Mixed,
required: true
},
userId: {
type: Schema.Types.Mixed,
required: true
},
timestamp: {
type: Date,
required: true
},
answers: [Schema.Types.Mixed]
}

@@ -33,3 +10,3 @@ //// TYPES

type FromFields<T extends Record<any, any>> = {
[Key in Fields<T>] :
[Key in Fields<T>]:
any extends T[Key]['type']

@@ -36,0 +13,0 @@ ? FromFields<T[Key]>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc