Skip to content

Commit

Permalink
create doc app and api folders; install mongoose & vite; start with r…
Browse files Browse the repository at this point in the history
…egister; b00tc4mp#160
  • Loading branch information
unknown authored and unknown committed Jul 30, 2024
1 parent eb33273 commit a181b82
Show file tree
Hide file tree
Showing 939 changed files with 189,487 additions and 81 deletions.
81 changes: 0 additions & 81 deletions staff/mateo-gomez/project/README.md

This file was deleted.

73 changes: 73 additions & 0 deletions staff/mateo-gomez/project/api/com/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class ContentError extends Error {
constructor(message) {
super(message)

this.name = this.constructor.name
}
}



class MatchError extends Error {
constructor(message) {
super(message)

this.name = this.constructor.name
}
}



class DuplicityError extends Error {
constructor(message) {
super(message)

this.name = this.constructor.name
}
}


class SystemError extends Error {
constructor(message) {
super(message)

this.name = this.constructor.name
}
}


class CredentialsError extends Error {
constructor(message) {
super(message)

this.name = this.constructor.name
}
}

class NotFoundError extends Error {
constructor(message) {
super(message)

this.name = this.constructor.name
}
}

export {
ContentError,
MatchError,
DuplicityError,
SystemError,
CredentialsError,
NotFoundError
}

const errors = {
ContentError,
MatchError,
DuplicityError,
SystemError,
CredentialsError,
NotFoundError
}

export default errors
13 changes: 13 additions & 0 deletions staff/mateo-gomez/project/api/com/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "com",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
75 changes: 75 additions & 0 deletions staff/mateo-gomez/project/api/com/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ContentError, MatchError } from "./errors.js"

const NAME_REGEX = /^[a-zA-Z=\[\]\{\}\<\>\(\)]{1,}$/
const USERNAME_REGEX = /^[\w-]+$/
const PASSWORD_REGEX = /^[\w-$%&=\[\]\{\}\<\>\(\)]{8,}$/
const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const ID_REGEX = /^[0-9a-z]+$/

function validateName(name, explain = 'name') {
if (typeof name !== 'string' || !NAME_REGEX.test(name))
throw new ContentError(`${explain} name is not valid`)
}

function validateSurname(surname, explain = 'surname') {
if (typeof surname !== 'string' || !NAME_REGEX.test(surname))
throw new ContentError(`${explain} is not valid`)
}

function validateUserName(username, explain = 'username') {
if (typeof username !== 'string' || !USERNAME_REGEX.test(username))
throw new ContentError(`${explain} is not valid`)
}

function validatePassword(password) {
if (typeof password !== 'string' || !PASSWORD_REGEX.test(password))
throw new ContentError('password is not valid')
}

function validatePasswordMatch(password, passwordRepeat) {
if (password !== passwordRepeat) {
throw new MatchError('password don\'t match')
}
}

function validateCallback(callback) {
if (typeof callback !== 'function')
throw new TypeError('callback is not a function')
}

function validateEmail(email) {
if (typeof email !== 'string' || !EMAIL_REGEX.test(email))
throw new ContentError('email is not valid')
}

function validateText(text, explain = 'text', maxLength = Infinity) {
if (typeof text !== 'string' || !text.length || text.length > maxLength) {
throw new ContentError(`${explain} is not valid`)
}
}

function validateURL(url, explain = 'url') {
if (typeof url !== 'string' || !url.startsWith('http')) {
throw new ContentError(`${explain} is not valid`)
}
}

function validateId(id, explain = 'id') {
if (!ID_REGEX.test(id) || typeof id !== 'string')
throw new ContentError(`${explain} is not valid`)
}

const validate = {
name: validateName,
surname: validateSurname,
username: validateUserName,
password: validatePassword,
passwordMatch: validatePasswordMatch,
callback: validateCallback,
email: validateEmail,
text: validateText,
url: validateURL,
id: validateId
}

export default validate
Loading

0 comments on commit a181b82

Please sign in to comment.