-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MONIT-60: ABM de restricción por paciente #1868
Open
JuanIRamirez
wants to merge
1
commit into
master
Choose a base branch
from
MONIT-60
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
modules/restriccion-huds/archivos/controller/restriccionHudsStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { make_Fs } from '../schemas/restriccionHudsStore'; | ||
import { Types } from 'mongoose'; | ||
import * as base64_stream from 'base64-stream'; | ||
import * as stream from 'stream'; | ||
|
||
const base64RegExp = /data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,(.*)/; | ||
|
||
export async function storeFile(base64, metadata) { | ||
try { | ||
const match = base64.match(base64RegExp); | ||
const mime = match[1]; | ||
const data = match[2]; | ||
const writePromise = new Promise((resolve) => { | ||
const uniqueId = new Types.ObjectId(); | ||
const input = new stream.PassThrough(); | ||
const decoder64 = base64_stream.decode(); | ||
const ImageFiles = make_Fs(); | ||
ImageFiles.writeFile( | ||
{ | ||
_id: uniqueId, | ||
filename: uniqueId + '.' + mime.split('/')[1], | ||
contentType: mime, | ||
metadata | ||
}, input.pipe(decoder64), | ||
(error, createdFile) => { | ||
resolve(createdFile); | ||
} | ||
); | ||
input.end(data); | ||
}); | ||
const result = await writePromise; | ||
return result; | ||
} catch (e) { | ||
return e; | ||
} | ||
} | ||
|
||
export async function readFile(id) { | ||
try { | ||
const ImageFiles = make_Fs(); | ||
const idFile = new Types.ObjectId(id); | ||
const contexto = await ImageFiles.findOne({ _id: idFile }); | ||
const imageStream = await ImageFiles.readFile({ _id: idFile }); | ||
return { | ||
file: contexto, | ||
stream: imageStream | ||
}; | ||
} catch (e) { | ||
return e; | ||
} | ||
} | ||
|
||
export async function deleteFile(id) { | ||
try { | ||
const ImageFiles = make_Fs(); | ||
const idFile = new Types.ObjectId(id); | ||
await ImageFiles.unlink(idFile, (error) => { }); | ||
return { | ||
file: idFile | ||
}; | ||
} catch (e) { | ||
return e; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
modules/restriccion-huds/archivos/schemas/restriccionHudsStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as mongoose from 'mongoose'; | ||
const { createBucket } = require('mongoose-gridfs'); | ||
|
||
export function make_Fs() { | ||
const CDAFilesSchema = createBucket({ | ||
collectionName: 'RestriccionHUDSStore', | ||
bucketName: 'RestriccionHUDSStore', | ||
mongooseConnection: mongoose.connection | ||
}); | ||
|
||
return CDAFilesSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export { restriccionHudsRouter } from './../restriccion-huds/restriccion-huds.routes'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { MongoQuery, ResourceBase } from '@andes/core'; | ||
import { restriccionHuds } from './restriccion-huds.schema'; | ||
import { readFile, storeFile, deleteFile } from './archivos/controller/restriccionHudsStore'; | ||
|
||
class restriccionHudsResource extends ResourceBase { | ||
Model = restriccionHuds; | ||
resourceName = 'restriccionHuds'; | ||
routesEnable = ['get', 'post', 'delete']; | ||
searchFileds = { | ||
id: { | ||
field: '_id', | ||
fn: MongoQuery.equalMatch | ||
}, | ||
}; | ||
} | ||
|
||
export const restriccionHudsCtr = new restriccionHudsResource({}); | ||
export const restriccionHudsRouter = restriccionHudsCtr.makeRoutes(); | ||
|
||
restriccionHudsRouter.get('/store/:id', (req, res, next) => { | ||
readFile(req.params.id).then((data: any) => { | ||
res.contentType(data.file.contentType); | ||
data.stream.on('data', (data2) => { | ||
res.write(data2); | ||
}); | ||
data.stream.on('end', () => { | ||
res.end(); | ||
}); | ||
}).catch(next); | ||
}); | ||
|
||
restriccionHudsRouter.post('/store', (req, res, next) => { | ||
const file = req.body.file; | ||
const metadata = req.body.metadata; | ||
storeFile(file, metadata).then((data) => { | ||
res.json(data); | ||
}).catch(next); | ||
}); | ||
|
||
restriccionHudsRouter.delete('/store/:id', async (req, res, next) => { | ||
const id = req.params.id; | ||
deleteFile(id).then((data) => { | ||
res.json(data); | ||
}).catch(next); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as mongoose from 'mongoose'; | ||
import { ModuloSchema } from '../../core/tm/schemas/modulos.schema'; | ||
|
||
export const restriccionHudsSchema = new mongoose.Schema({ | ||
id: mongoose.Schema.Types.ObjectId, | ||
fecha: { type: Date, default: Date.now }, | ||
titulo: String, | ||
descripcion: String, | ||
modulo: { | ||
type: ModuloSchema | ||
}, | ||
imagenes: mongoose.Schema.Types.Mixed, | ||
activa: Boolean | ||
}); | ||
|
||
export const restriccionHuds = mongoose.model('restriccionHuds', restriccionHudsSchema, 'restriccionHuds'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
al ser de tipo any está guardando solo documento y del usuario restringido, no del que crea la restricción o la actualiza. No sería mejor para created o updated usar AuditPlugin?