-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Avoid delete
syntax when pack models
#4078
Labels
packages/backend
Server side specific issue/PR
💚Refactor
Rewriting code without changing behavior
🔒Security
Security related issue/PR
Comments
acid-chicken
added
packages/backend
Server side specific issue/PR
💚Refactor
Rewriting code without changing behavior
🔒Security
Security related issue/PR
labels
Feb 1, 2019
Related #4018 |
例えばこんな感じ。 import * as mongo from 'mongodb';
import * as deepcopy from 'deepcopy';
import db from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
import { pack as packUser } from './user';
const AbuseUserReport = db.get<IAbuseUserReport>('abuseUserReports');
AbuseUserReport.createIndex('userId');
AbuseUserReport.createIndex('reporterId');
AbuseUserReport.createIndex(['userId', 'reporterId'], { unique: true });
export default AbuseUserReport;
export interface IAbuseUserReport {
_id: mongo.ObjectID;
createdAt: Date;
userId: mongo.ObjectID;
reporterId: mongo.ObjectID;
comment: string;
}
type ReportType = string | mongo.ObjectID | IAbuseUserReport;
export const find = async (report: ReportType) =>
isObjectId(report) ? await AbuseUserReport.findOne({ _id: report }) :
typeof report === 'string' && mongo.ObjectID.isValid(report) ? await AbuseUserReport.findOne({ _id: new mongo.ObjectID(report) }) :
report as IAbuseUserReport;
export const packMany = (reports: ReportType[]) =>
Promise.all(reports.map(pack));
export const pack = async (report: ReportType) => {
const source = await find(report);
return {
id: source._id,
reporter: await packUser(source.reporterId, null, { detail: true }),
user: await packUser(source.userId, null, { detail: true })
};
}; |
(どこら辺が |
直接関係ないですが 最初から
|
その通りです。 |
実質 Duplicate of #4018 |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
packages/backend
Server side specific issue/PR
💚Refactor
Rewriting code without changing behavior
🔒Security
Security related issue/PR
Summary
#4045 のような消し忘れが危ない。
The text was updated successfully, but these errors were encountered: